-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDisplayStats.java
115 lines (98 loc) · 3.63 KB
/
DisplayStats.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package application;
import java.text.DecimalFormat;
import java.util.ArrayList;
public class DisplayStats {
private final static String[] MONTHS_OF_YEAR = {"January", "February", "March", "April", "May", //Stores month of years as numbers
"June", "July", "August", "September", "October", "November", "December"};
DecimalFormat df = new DecimalFormat("#.00");
Farm farm;
public DisplayStats(Farm farm) {
this.farm = farm;
}
/**
* returns total and percent total of each month for FarmReport as a 2D matrix with 1st row as total
* @param farmID
* @param year
* @return
* @throws Exception
*/
public ArrayList<String> farmReportResult(String farmID, String year) throws Exception{
ArrayList<Farm.Details> list = farm.farmReport(farmID, year);
ArrayList<String> percentArray = new ArrayList<String>();
int total = 0;
//Traverse through list to get total sum
for (int j = 0; j < list.size(); j++) {
total += list.get(j).getMilkWeight();
}
//Compute each months percent of the total
for (int i = 0; i < list.size(); i++) {
double percent = list.get(i).getMilkWeight() / (double)total * 100;
percentArray.add(df.format(percent) + "%");
}
return percentArray;
}
/**
* returns total and percent total of each farm for AnnualReport as a 2D matrix with 1st row as total
* @param year
* @return
* @throws Exception
*/
public ArrayList<String> annualReportResult(String year) throws Exception{
ArrayList<Farm.Details> list = farm.annualReport(year);
ArrayList<String> percentArray = new ArrayList<String>();
int total = 0;
//Traverse through list to get total sum
for (int j = 0; j < list.size(); j++) {
total += list.get(j).getMilkWeight();
}
//Compute each farms percent of the total
for (int i = 0; i < list.size(); i++) {
double percent = list.get(i).getMilkWeight() / (double)total * 100;
percentArray.add(df.format(percent) + "%");
}
return percentArray;
}
/**
* returns total and percent total of each farm for Monthly Report as a 2D matrix with 1st row as total
* @param month
* @param year
* @return
* @throws Exception
*/
public ArrayList<String> monthlyReportResult(int month, int year) throws Exception{
ArrayList<Farm.Details> list = farm.monthlyReport(month, year);
ArrayList<String> percentArray = new ArrayList<String>();
int total = 0;
//Traverse through list to get total sum
for (int j = 0; j < list.size(); j++) {
total += list.get(j).getMilkWeight();
}
//Compute each farms percent of the total
for (int i = 0; i < list.size(); i++) {
double percent = list.get(i).getMilkWeight() / (double)total * 100;
percentArray.add(df.format(percent) + "%");
}
return percentArray;
}
/**
* returns total and percent total of each farm for Date-Range Report as a 2D matrix with 1st row as total
* @param year
* @return
* @throws Exception
*/
public ArrayList<String> dateRangeResult(int year, int month, int day, int endMonth, int endDay) throws Exception{
ArrayList<Farm.Details> list = farm.dateRange(year, month, day, endMonth, endDay);
ArrayList<String> percentArray = new ArrayList<String>();
int total = 0;
//Traverse through list to get total sum
for (int j = 0; j < list.size(); j++) {
total += list.get(j).getMilkWeight();
}
//Compute each entries percent of the total
for (int i = 0; i < list.size(); i++) {
double percent = list.get(i).getMilkWeight() / (double)total * 100;
percentArray.add(df.format(percent) + "%");
}
return percentArray;
}
}