I've been set the task of creating a basic earthquake monitoring program.
The classes for the program are:
Earthquake: store and retrieve data on magnitude, position (latitude & longitude) and year.
Observatory: store and retrieve data on name of observatory, country in which it's located, year in which observations began, area covered by observatory (in sq/kms) and list of earthquakes recorded by it.
Includes methods to return: the largest magnitude earthquake recorded by the observatory, the average earthquake magnitude recorded by the observatory, a list of all methods recorded by the observatory with a magnitude greater than a given number.
Monitoring: Holds information about all observatories. Includes methods to return: the observatory with the largest average magnitude, the largest magnitude earthquake ever recorded, a list of all earthquakes recorded with a magnitude greater than a given number
Any help would be hugely appreciated.
import java.util.ArrayList;
public class Monitoring {
private ArrayList<Observatory> observatoryList;
public Monitoring() {
observatoryList = new ArrayList<>();
}
public Observatory getAverageMax() {
double x = 0.0;
Observatory ans = null;
for (Observatory o: observatoryList) {
if (x < o.getAverage()) {
x = o.getAverage();
ans = o;
}
}
return ans;
}
public int largestMagnitude() {
int ans = 0;
for (Observatory o: observatoryList) {
ans = Math.max(ans, o.largestMagnitude());
}
return ans;
}
public ArrayList<Earthquake> greater(int n) {
ArrayList<Earthquake> ans = new ArrayList<>();
for (Observatory o: observatoryList) {
ArrayList<Earthquake> earthquakes = o.greater(n);
for (Earthquake e: earthquakes) {
ans.add(e);
}
}
return ans;
}
}
class Earthquake {
private int magnitude;
private double latitude;
private double longitude;
private int year;
public Earthquake(int newMagnitude, double newLatitude, double newLongitude, int newYear) {
magnitude = newMagnitude;
latitude = newLatitude;
longitude = newLongitude;
year = newYear;
}
public int getMagnitude() {
return magnitude;
}
public double getLatitude() {
return latitude;
}
public double getLongitude() {
return longitude;
}
public int getYear() {
return year;
}
}
class Observatory {
private String name;
private String country;
private int year;
private double area;
private ArrayList<Earthquake> earthquakeList;
public Observatory(String newName, String newCountry, int newYear, double newArea) {
name = newName;
country = newCountry;
year = newYear;
area = newArea;
earthquakeList = new ArrayList<>();
}
public String getName() {
return name;
}
public String getCountry() {
return country;
}
public int getYear() {
return year;
}
public double getArea() {
return area;
}
public void addEarthquake(Earthquake e) {
earthquakeList.add(e);
}
public int largestMagnitude() {
int ans = 0;
for (Earthquake e: earthquakeList) {
ans = Math.max(ans, e.getMagnitude());
}
return ans;
}
public double getAverage() {
double s = 0.0;
for (Earthquake e: earthquakeList) {
s += e.getMagnitude();
}
return s / earthquakeList.size();
}
public ArrayList<Earthquake> greater(int n) {
ArrayList<Earthquake> ans = new ArrayList<>();
for (Earthquake e: earthquakeList) {
if (e.getMagnitude() > n) {
ans.add(e);
}
}
return ans;
}
}
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Learn more about our help with Assignments:
JavaJSPJSF