KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > Statistic


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 import java.util.*;
17
18 import org.apache.commons.logging.Log;
19 import org.apache.commons.logging.LogFactory;
20
21 public class Statistic {
22     private static Log log = LogFactory.getLog(Statistic.class);
23         
24     private int summary;
25     private DayRecord records[];
26
27     // inserts random statistic data
28
public Statistic(){
29         int rows = 3;
30         records = new DayRecord[rows];
31         
32         Calendar cal = Calendar.getInstance();
33         Random rnd = new Random();
34         
35         for (int i = 0; i < rows; i++){
36             cal.set(2004, 5, i);
37             records[i] = new DayRecord(cal.getTime(), rnd.nextInt(5000));
38         }
39         
40     }
41     
42     public DayRecord[] getRecords() {
43         return records;
44     }
45
46     public void setRecords(DayRecord[] records) {
47         this.records = records;
48     }
49
50     public int getSummary() {
51         summary = 0;
52         
53         for (int i = 0; i < records.length; i++)
54             summary += records[i].getVisitors();
55         
56         return(summary);
57     }
58     
59 }
Popular Tags