Answered step by step
Verified Expert Solution
Question
1 Approved Answer
import javax.swing.JOptionPane; import java.io . File; import java.io . FileNotFoundException; import java.util.Scanner; import java.text.ParseException; public class AlertProcessor { public static void main ( String [
import javax.swing.JOptionPane;
import java.ioFile;
import java.ioFileNotFoundException;
import java.util.Scanner;
import java.text.ParseException;
public class AlertProcessor
public static void mainString args
CountyList countyList new CountyList;
AlertList alertList new AlertList;
Populate county list
popCountyListcountyList;
Process alerts from file
processAlertsFromFilealertList countyList;
Sort alerts
alertList.sortAlerts;
Output alerts
showOutputInDialogalertList countyList;
Method to populate county list
private static void popCountyListCountyList countyList
try
File file new FileD:comp SecurityChecksrcfipsCountytxt;
Scanner scanner new Scannerfile;
while scannerhasNextLine
String line scanner.nextLine;
Split the line by comma to get FIPS code and county data
String parts line.split; Split only into two parts
if partslength
String countyFIPSCode partstrim;
String countyData partssplit; Split only into two parts
if countyDatalength
String countyName countyDatatrim;
int population Integer.parseIntcountyDatatrim;
County county new CountycountyFIPSCode population, countyName;
countyList.addCountycounty;
else
System.out.printlnInvalid data format: line;
else
System.out.printlnInvalid data format: line;
scanner.close;
catch FileNotFoundException e
eprintStackTrace;
Method to process alerts from file
private static void processAlertsFromFileAlertList alertList, CountyList countyList
try
File file new FileD:comp SecurityChecksrcalertstxt;
Scanner scanner new Scannerfile;
while scannerhasNextLine
String line scanner.nextLine;
String parts line.split;
try
Alert alert new Alertparts parts parts parts;
alertList.addAlertalert;
catch ParseException e
System.err.printlnFailed to parse alert: egetMessage;
scanner.close;
catch FileNotFoundException e
eprintStackTrace;
Method to output alerts
private static void showOutputInDialogAlertList alertList, CountyList countyList
StringBuilder output new StringBuilder;
for Alert alert : alertList.getAlerts
output.appendalertgenerateDescriptioncountyListappend
;
JOptionPane.showMessageDialognull output.toString "Alerts", JOptionPane.INFORMATIONMESSAGE;
Invalid data format: Wood County, WV
Invalid data format: Wyoming County, WV
Invalid data format: WISCONSIN
Invalid data format: Adams County, WI
Invalid data format: Ashland County, WI
Invalid data format: Barron County, WI
Invalid data format: Bayfield County, WI I need the code to read the fipsCounty correctly
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