-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMonitoring.java
More file actions
80 lines (74 loc) · 2.65 KB
/
Copy pathMonitoring.java
File metadata and controls
80 lines (74 loc) · 2.65 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
import java.util.ArrayList;
/**
* A class which contains information about all observatories.
*/
public class Monitoring
{
public ArrayList<Observatory> observatoryList;
private int index;
private ArrayList<Earthquake> earthquakesRecordGreaterGivenNumber;
/**
* Construct a Monitory object constructor.
*/
public Monitoring()
{
observatoryList = new ArrayList<>();
earthquakesRecordGreaterGivenNumber = new ArrayList<>();
}
/**
* The method calculates the average earthquake magnitude of every observatory record in Monitoring, and then
* choose the largest average earthquake magnitude.
* @return The largest average earthquake, with type Observatory
*/
public Observatory getLargestAverageObservatory()
{
double value = observatoryList.get(0).getAverageMagnitude();
index = 0;
for (int i = 1; i < observatoryList.size(); i++)
{
if (value < observatoryList.get(i).getAverageMagnitude())
{
value = observatoryList.get(i).getAverageMagnitude();
index = i;
}
}
return observatoryList.get(index);
}
/**
* The method calculates the largest earthquake magnitude recorded in all the observatories.
* @return the largest magnitude earthquake, with type Observatory
*/
public Observatory getLargestMagnitudeRecord()
{
double largestRecord = observatoryList.get(0).getLargestMagnitude();
index = 0;
for (int i = 1; i < observatoryList.size(); i++)
{
if (largestRecord < observatoryList.get(i).getLargestMagnitude())
{
largestRecord = observatoryList.get(i).getLargestMagnitude();
index = i;
}
}
return observatoryList.get(index);
}
/**
* The method finds the earthquake recorded at the observatory with a
* magnitude greater than a given number.
* @param givenNumber An earthquake magnitude, with double type
* @return ArrayList of earthquake magnitude greater than the given number
*/
public ArrayList<Earthquake> getAllGreaterThanGivenNumber(double givenNumber)
{
earthquakesRecordGreaterGivenNumber.clear();
for (Observatory element : observatoryList)
{
earthquakesRecordGreaterGivenNumber.addAll(element.getEarthquakesGreaterThanGivenNumber(givenNumber));
}
if (earthquakesRecordGreaterGivenNumber.isEmpty())
{
System.out.println("There is no number greater than " + givenNumber);
}
return earthquakesRecordGreaterGivenNumber;
}
}