forked from Denisolt/CSCI-160
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRainfallClass.java
More file actions
81 lines (75 loc) · 2.05 KB
/
RainfallClass.java
File metadata and controls
81 lines (75 loc) · 2.05 KB
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
/* Denisolt Shakhbulatov
* 11/03/2015
_______________________________
+ RainfallClass +
+______________________________
+ -String[]months +
+ -double[]: rain +
+ -double[]: total +
+______________________________
+ +getTotal():double +
+ +getAverage():double +
+ +getMax():double +
+ +getMin():double +
_______________________________
*/
public class RainfallClass
{
String[] months = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
double[] rain = {0.40, 0.94, 3.21, 3.74, 1.73, 1.03, 1.27, 2.58, 6.98, 6.90, 2.80, 2.53};
public static void main(String [] arg)
{
RainfallClass tx = new RainfallClass();
double total = tx.totalrain();
double average = tx.averagerain(total);
double min = tx.min();
double max = tx.max();
tx.showresult();
System.out.println("total " + total);
System.out.println("average " + average);
System.out.println("max " + max);
System.out.println("min " + min);
}
public double totalrain()
{
double total = 0;
for (int index=0; index<rain.length; index++)
{
total = total+rain[index];
}
return total;
}
public double averagerain(double total)
{
double average = total/rain.length;
return average;
}
public double min()
{
double min=0;
for (int index=0; index<rain.length;index++)
{
if(min<=rain[index])
min = rain[index];
break;
}
return min;
}
public double max()
{
double max=0;
for (int index=0; index<rain.length;index++)
{
if(max<=rain[index])
max = rain[index];
}
return max;
}
public void showresult()
{
for (int index=0; index<rain.length; index++)
{
System.out.println(months[index] +"\t"+ rain[index]);
}
}
}