-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMesoInherit.java
More file actions
173 lines (145 loc) · 4.01 KB
/
MesoInherit.java
File metadata and controls
173 lines (145 loc) · 4.01 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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
public class MesoInherit extends MesoAbstract {
/**
* Array list to hold the names of all the stations
*/
protected static ArrayList<String> stations = new ArrayList<String>();
/**
* MesoStation object containting the stID
*/
private MesoStation mesoStation;
/**
* default empty constructor
*/
public MesoInherit()
{
stations = new ArrayList<String>();
mesoStation = null;
}
/**
*
* @param Receives mesoStation object and assigns it to the class level
* mesoStation
* @throws IOException
*/
public MesoInherit(MesoStation mesoStation) throws IOException
{
readStations();
this.mesoStation = mesoStation;
}
/**
* @Override Remove the Ceiling, Floor, and Average values in an int array
*/
int[] calAverage()
{
int[] average = new int[3];
average[0] = getCeiling();
average[1] = getFloor();
average[2] = getAverage();
return average;
}
/**
* @Overide Returns the letterAverage which is just the getAverage() casted to a
* char
*/
protected char letterAverage()
{
return (char) getAverage();
}
/**
* Creates a list of station from the txt file. Each line of the txt represents
* a single station.
*
* @param filename The file to read from.
* @throws IOException
*/
public static void readStations() throws IOException
{
BufferedReader br = new BufferedReader(new FileReader("Mesonet.txt"));
String strg;
// Throw out unnecessary data
strg = br.readLine();
strg = br.readLine();
strg = br.readLine();
// First row containing data
strg = br.readLine();
while (strg != null) {
strg = strg.substring(1, 5);
stations.add(strg);
strg = br.readLine();
}
br.close();
}
/**
* for loop to add up ascii values and get ceiling division
*
* @return Returns an the sum of the ascii values divided by the length of the
* mesoStation ID and performs ceiling division
*/
public int getCeiling()
{
// initilizing return
int ceiling = 0;
// variable to hold the sum of all the ascii values
double sum = 0.0;
// variable to hold the double division of the sum 4 to be able to cast ceiling
// as an int
double average = 0.0;
// for loop to add up all the ascii values
for (int i = 0; i < mesoStation.getStID().length(); i++)
{
sum += mesoStation.getStID().charAt(i);
}
// getting the raw double ascii average
average = sum / mesoStation.getStID().length();
// performing ceiling rounding on the ascii average and casting to int and
// assigning it to ceiling
ceiling = (int) Math.ceil(average);
return ceiling;
}
// for loop to add up ascii values and get floor division
public int getFloor()
{
// initilizing return
int floor = 0;
// variable to hold the sum of all the ascii values
double sum = 0.0;
// variable to hold the double division of the sum 4 to be able to cast ceiling
// as an int
double average = 0.0;
// for loop to add up all the ascii values
for (int i = 0; i < mesoStation.getStID().length(); i++)
{
sum += mesoStation.getStID().charAt(i);
}
// getting the raw double ascii average
average = sum / mesoStation.getStID().length();
// performing floor division on the ascii average and casting to int and
// assigning it to ceiling
floor = (int) Math.floor(average);
return floor;
}
// for loop to add up ascii values and get ceiling division
public int getAverage()
{
// initilizing return
int avg = 0;
// variable to hold the sum of all the ascii values
double sum = 0.0;
// variable to hold the double division of the sum 4 to be able to cast ceiling
// as an int
double rawAverage = 0.0;
// for loop to add up all the ascii values
for (int i = 0; i < mesoStation.getStID().length(); i++)
{
sum += mesoStation.getStID().charAt(i);
}
// getting the raw double ascii average
rawAverage = sum / mesoStation.getStID().length();
avg = (int)Math.round(rawAverage);
return avg;
}
}