-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObservatory.java
More file actions
165 lines (150 loc) · 5.11 KB
/
Copy pathObservatory.java
File metadata and controls
165 lines (150 loc) · 5.11 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
import java.util.ArrayList;
/**
* A class which contains the observatory information.
*/
public class Observatory
{
private String observatoryName;
private String observatoryCountryName;
private int observatoryStartedYear;
private double observatoryCoverArea; // in square kilometres
public ArrayList<Earthquake> earthquakeList;
private double averageMagnitude;
private ArrayList<Earthquake> earthquakesGreaterThanGivenNumber;
/**
* Construct an Observatory object constructor.
* @param observatoryName the name of the observatory, with type String.
* @param observatoryCountryName the observatory's country name, with type String.
* @param observatoryStartedYear the observatory started year, with type int.
* @param observatoryCoverArea the observatory covered area(in square kilometers), with type double.
*/
public Observatory(String observatoryName, String observatoryCountryName, int observatoryStartedYear, double observatoryCoverArea)
{
this.observatoryName = observatoryName;
this.observatoryCountryName = observatoryCountryName;
this.observatoryStartedYear = observatoryStartedYear;
this.observatoryCoverArea = observatoryCoverArea;
earthquakeList = new ArrayList<>();
earthquakesGreaterThanGivenNumber = new ArrayList<>();
}
/**
* The method calculates the largest magnitude earthquake recorded by the observatory.
* @return the largest magnitude earthquake, with the type double
*/
public double getLargestMagnitude()
{
double largetsMagnitude = earthquakeList.get(0).getMagnitude();
for (int i = 1; i < earthquakeList.size(); i++)
{
if (largetsMagnitude < earthquakeList.get(i).getMagnitude())
{
largetsMagnitude = earthquakeList.get(i).getMagnitude();
}
}
return largetsMagnitude;
}
/**
* The method calculates the average earthquake magnitude recorded at the observatory.
* @return the average magnitude earthquake, with the type double
*/
public double getAverageMagnitude()
{
double total = 0;
for (int i = 0; i < earthquakeList.size(); i++)
{
double element = earthquakeList.get(i).getMagnitude();
total = total + element;
}
if (earthquakeList.size() > 0)
{
averageMagnitude = total / earthquakeList.size();
}
else
{
return 0;
}
return averageMagnitude;
}
/**
* 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> getEarthquakesGreaterThanGivenNumber(double givenNumber)
{
earthquakesGreaterThanGivenNumber.clear();
for (Earthquake element : earthquakeList)
{
if (element.getMagnitude() > givenNumber)
{
earthquakesGreaterThanGivenNumber.add(element);
}
}
return earthquakesGreaterThanGivenNumber;
}
/**
* Get the observatory name.
* @return the observatory name as type String
*/
public String getObservatoryName()
{
return observatoryName;
}
/**
* Set the observatory name.
* @param observatoryName the observatory name, with the type String
*/
public void setObservatoryName(String observatoryName)
{
this.observatoryName = observatoryName;
}
/**
* Get the observatory's country name.
* @return the observatory's country name as type String
*/
public String getObservatoryCountryName()
{
return observatoryCountryName;
}
/**
* Set the observatory's country name.
* @param observatoryCountryName the observatory's country name, with the type String
*/
public void setObservatoryCountryName(String observatoryCountryName)
{
this.observatoryCountryName = observatoryCountryName;
}
/**
* Get the observatory started year.
* @return the observatory started year as type int
*/
public int getObservatoryStartedYear()
{
return observatoryStartedYear;
}
/**
* Set the observatory started year.
* @param observatoryStartedYear the observatory started year, with the type int
*/
public void setObservatoryStartedYear(int observatoryStartedYear)
{
this.observatoryStartedYear = observatoryStartedYear;
}
/**
* Get the observatory cover area.
* @return the observatory cover area as type double
*/
public double getObservatoryCoverArea()
{
return observatoryCoverArea;
}
/**
* Set the observatory cover area.
* @param observatoryCoverArea the observatory cover area, with the type double
*/
public void setObservatoryCoverArea(double observatoryCoverArea)
{
this.observatoryCoverArea = observatoryCoverArea;
}
}