-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPosAvg.java
More file actions
90 lines (73 loc) · 1.48 KB
/
PosAvg.java
File metadata and controls
90 lines (73 loc) · 1.48 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
import java.io.IOException;
public class PosAvg extends MesoInherit
{
/**
* station id being received
*/
private String stId;
/**
* station that is n-1
*/
private String stationMinus1;
/**
* station that is n+1
*/
private String stationPlus1;
/**
* station that is n-2
*/
private String stationMinus2;
/**
* station that is n+1
*/
private String stationPlus2;
/**
* @param stID the name of the station being received
* @throws IOException
*/
public PosAvg(String stID) throws IOException
{
readStations();
this.stId = stID;
}
/**
*
* @return the index of the station + 1 since array list begins at [0)
*/
public int indexOfStation()
{
int index = 0;
for (int i = 0; i < stations.size(); i++)
{
if (stations.get(i).equalsIgnoreCase(stId))
{
index = i + 1;
}
}
otherStations(index);
return index;
}
/**
* Finds the stations n +- 1 and n +- 2
* @param index
*/
public void otherStations(int index)
{
index = index - 1;
if (index > 1 && index < 120)
{
this.stationMinus1 = stations.get(index - 1);
this.stationMinus2 = stations.get(index - 2);
this.stationPlus1 = stations.get(index + 1);
this.stationPlus2 = stations.get(index + 2);
}
}
/**
* Class toString that returns properly formatted string
*/
public String toString()
{
return String.format("This index is average of %s and %s, %s and %s, and so on.", stationMinus1, stationPlus1,
stationMinus2, stationPlus2);
}
}