Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Not reading fileimport java.io . File; import java.io . FileNotFoundException; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Scanner; class Earthquake { private Date dateTime; private
Not reading fileimport java.ioFile;
import java.ioFileNotFoundException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
class Earthquake
private Date dateTime;
private double latitude;
private double longitude;
private double magnitude;
private String location;
public EarthquakeString dateTime, double latitude, double longitude, double magnitude, String location
throws ParseException
this.dateTime new SimpleDateFormatyyyyMMddTHH:mm:ssSSSZparsedateTime;
this.latitude latitude;
this.longitude longitude;
this.magnitude magnitude;
this.location location;
public boolean isInRegiondouble minLat, double maxLat, double minLon, double maxLon
return latitude minLat && latitude maxLat && longitude minLon && longitude maxLon;
public boolean isInRangeDate minDate, Date maxDate
return dateTime.compareTominDate && dateTime.compareTomaxDate;
public boolean isMagnitudeGreaterOrEqualdouble minMag
return magnitude minMag;
public String formattedOutput
SimpleDateFormat outputFormat new SimpleDateFormatdd MMM yy HHmmZ;
String formattedDateTime outputFormat.formatdateTime;
return String.formatsff Mag: fs formattedDateTime, latitude, Math.abslongitude
magnitude, location;
public class quakeFinder
private static final int MAXLENGTH ;
private Earthquake earthquakes new EarthquakeMAXLENGTH;
private int numQuakes ;
public static void mainString args
quakeFinder quakeFinder new quakeFinder;
quakeFinder.readDataFromFilequakestxt;
quakeFinder.runQueryInterface;
public void readDataFromFileString filename
try Scanner scanner new Scannernew Filequakestxt
while scannerhasNextLine
String line scanner.nextLine;
String quakeData line.split;
if quakeDatalength
try
earthquakesnumQuakes new EarthquakequakeData Double.parseDoublequakeData
Double.parseDoublequakeData Double.parseDoublequakeData quakeData;
numQuakes;
catch ParseException NumberFormatException e
System.out.printlnError parsing earthquake data: egetMessage;
else
System.out.printlnInvalid earthquake data format: line;
catch FileNotFoundException e
System.out.printlnFile not found: "quakes.txt;
public void runQueryInterface
Scanner scanner new ScannerSystemin;
while true
System.out.printlnEnter query R D M or Q to quit:";
String input scanner.nextLinetrim;
if inputequalsIgnoreCaseQ
break;
if isValidQueryinput
processQueryinput;
else
System.out.printlnInvalid query format. Please try again.";
scanner.close;
private boolean isValidQueryString input
Validate the query format egR D T::Z T::Z
M
String tokens input.splits;
if tokenslength tokens.length
return false;
if tokensequalsIgnoreCaseR && tokensequalsIgnoreCaseD && tokensequalsIgnoreCaseM
return false;
switch tokens
case R:
return tokens.length && isDoubletokens && isDoubletokens && isDoubletokens;
case D:
return tokens.length && isValidDatetokens && isValidDatetokens;
case M:
return tokens.length && isDoubletokens;
default:
return false;
private void processQueryString input
String tokens input.splits;
switch tokens
case R:
double minLat Double.parseDoubletokens;
double maxLat Double.parseDoubletokens;
double minLon Double.parseDoubletokens;
double maxLon Double.parseDoubletokens;
printQuakesInRegionminLat maxLat, minLon, maxLon;
break;
case D:
try
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started