Reputation: 85
My Java assignment is to to write a Java application that uses data from a text file with earth quake information and generate a report with:
the count of the number of values read,
the total sum of the magnitudes,
the average magnitude value (to 2 decimal places),
the maximum magnitude value, where it happened and when
the minimum magnitude value, where it happened and when
I can get the file to open using File and Scanner classes but I can't get it to read extract only a double (i.e the magnitudes below: 1.6, 1.8, ect.). I can get it to count the number of lines. I've tried deliminators with the Scanner and Pattern classes and then using Double parse but it won;t work. I'm a rookie for sure and this class just took a leap.
Example of input from text file:
1.6,"Southern California","Wednesday, January 18, 2012 19:19:12 UTC"
1.8,"Southern California","Wednesday, January 18, 2012 19:03:00 UTC"
1.8,"Southern California","Wednesday, January 18, 2012 18:46:53 UTC"
4.7,"Bonin Islands, Japan region","Wednesday, January 18, 2012 18:20:40 UTC"
1.6,"Southern California","Wednesday, January 18, 2012 17:58:07 UTC"
Upvotes: 0
Views: 688
Reputation: 1059
Try this
String str = "1.6,california,wednesday,whatever";
String[] results = str.split(",");
Double testDouble = Double.valueOf(str[0]);
Upvotes: 1