so this is my code. I am attempting to read input from a .txt file that has data about earthquakes. Below is the actual data. My code should store each occurence of an earthquake as an ArrayList object. I have a class called Earthquake. The code of the class is below too. I the error I get is also copied below. Could someone help me figure out what is wrong? I know the error is in the EarthquakeDemo
Here is the error I get when I run the EarthquakeDemo code
----jGRASP exec: java EarthquakeDemo
time latitude longitude depth mag place
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:909)
at java.util.Scanner.next(Scanner.java:1530)
at java.util.Scanner.nextDouble(Scanner.java:2456)
at EarthquakeDemo.main(EarthquakeDemo.java:20)
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
earthquakeUpdated.txt
time latitude longitude depth mag place
2013-10-01T20:44 38.834 -122.802 2.3 2.5 California
2013-10-01T20:17 62.254 -150.816 46 2.6 Alaska
2013-10-01T19:41 55.7806 -34.7243 12.03 5.2 Reykjanes Ridge
2013-10-01T19:26 36.1288 -97.6639 5.01 3 Oklahoma
2013-10-01T17:51 38.8343 -122.795 2.5 2.7 California
EARTHQUAKE CLASS
public class Earthquake
{
private String time;
private double latitude;
private double longitude;
private double depth;
private double magnitude;
private String place;
/* +Earthquake (lat: double, long: double): void
+setTime(t: String): void
+setDepth(d: double) void
+setMagnitude(m: double): void
+ setPlace(p: String): void
+ getPlace(): String
+ getMagnitude(): double
+toString():String*/
public void Earthquake(double lat, double longi)
{
latitude = lat;
longitude = longi;
}
public void setTime(String t)
{
time = t;
}
public void setDepth(double d)
{
depth=d;
}
public void setMagnitude(double m)
{
magnitude = m;
}
public void setPlace(String p)
{
place = p;
}
public String getPlace()
{
return place;
}
public double getMagnitude()
{
return magnitude;
}
public String toString()
{
String stat= "An earthquake in "+place+ " with magnitude of "+ magnitude+ " occurred at "+time;
return stat;
}
}
EarthquakeDemo
import java.util.*;
import java.io.*;
public class EarthquakeDemo
{
public static void main(String [] args)throws IOException
{
ArrayList<Earthquake> list = new ArrayList<Earthquake>();
File file = new File("earthquakeUpdated.txt");
Scanner infile = new Scanner(file);
String ignore = infile.nextLine();
System.out.println(ignore);
int i=0;
while(infile.hasNext())
{
Earthquake temp = new Earthquake();
temp.setTime(infile.next());
temp.Earthquake(infile.nextDouble(),infile.nextDou ble());
temp.setDepth(infile.nextDouble());
temp.setMagnitude(infile.nextDouble());
temp.setPlace(infile.nextLine());
list.add(i, temp);
i++;
}
infile.close();
for(int x =0; x<list.size();x++)
{
System.out.println(list.get(x).toString());
}
}
}