The java classes for reading in live earthquake data from the last 7 days is giv
ID: 3629596 • Letter: T
Question
The java classes for reading in live earthquake data from the last 7 days is given. The classes for creating new cities and earthquakes are given.(picture below, earthquake is very similar but not shown).
You should use one linked list that stores all earthquakes. Another linked list to store all cities that exceed the population threshold. The information of what cities are within the range of a specific earthquake should be stored as a linked list that is attached to that earthquake.(city is in range if distance is at most magnitude *100)(finding distance method is not as important i really need help with implementing the 2d linked lst)
The program to be created should print a list of all earthquakes(with # cities and total population affected)
After it should print the earthquake with the highest population affected with a list of all cities affected.
The second pictue below prints a list of all earthquake plus info(not including cities in range or population). Then prints all cities above threshold with info
Explanation / Answer
this is what i have implemented on the earthquake using linkedlist, it may not be like what you need. but you can reference the source code.
what this output:
1) all the information entered. name, country..
2) print the country that is the most populated (only one country will be shown)
3) print the country that exceeds the threshold.
if you required any other methods, please PM me, i would send the part to you.
import java.util.*;
class City{
public String name;
public String country;
public double longitude;
public double latitude;
public int population;
public City(){
name = new String("");
country = new String("");
population =0;
longitude = 0.0;
latitude = 0.0;
}
public City(String n, String c, int pop, double lat, double lon){
name = new String(n);
country = new String(c);
population = pop;
longitude = lon;
latitude = lat;
}
public void print(){
System.out.print(name+" ("+country+", pop: "+population+", coord: "+latitude+"/"+longitude+")");
System.out.println();
}
}
public class EarthQuakeMonitor {
public static void main(String[] args) {
System.out.println("Earthquakes:");
City country = null;
Scanner sc = new Scanner(System.in);
LinkedList<City> listC = new LinkedList<City>();
LinkedList<Integer> listM = new LinkedList<Integer>();
// storing the info for city in one linkedlist, storing the magnitude of the earthquake in the other.
while(sc.hasNext()){
country = new City(sc.next(), sc.next(), sc.nextInt(),sc.nextDouble(),sc.nextDouble());
listC.add(country);
listM.add(sc.nextInt());
}
// printing what has been input into the system.
System.out.println(" The information that just been entered into the system :");
for(int i = 0; i < listC.size(); i++){
System.out.printf("%d ", listM.get(i));
listC.get(i).print();
}
System.out.println();
// checking the city with most pop, afterwhich print only the most populated country.
int indexP = 0; //the index of the country which has the most pop.
int noP = 0; // the number of pop, used in the for loop to compare with other country and storing the most pop.
for (int i = 0; i < listC.size(); i++){
if(noP < listC.get(i).population){
noP = listC.get(i).population;
indexP = i;
}
}
System.out.printf("The city with the most pop is: %s", listC.get(indexP).country);
listC.get(indexP).print(); //print out the info for the most populated country.
System.out.println();
// check and print out only country that exceed threshold
int threshold = 10000; // threshold for the earthquake.
System.out.println("The countries that exceed the threshold:");
for(int i =0; i< listM.size(); i++)
{
if(listM.get(i) > threshold){
listC.get(i).print();
}
}
System.out.println();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.