Answered step by step
Verified Expert Solution
Link Copied!

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.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.text.ParseException;
public class AlertProcessor {
public static void main(String[] args){
CountyList countyList = new CountyList();
AlertList alertList = new AlertList();
// Populate county list
popCountyList(countyList);
// Process alerts from file
processAlertsFromFile(alertList, countyList);
// Sort alerts
alertList.sortAlerts();
// Output alerts
showOutputInDialog(alertList, countyList);
}
// Method to populate county list
private static void popCountyList(CountyList countyList){
try {
File file = new File("D:\\comp 2\\SecurityCheck\\src\\fipsCounty.txt");
Scanner scanner = new Scanner(file);
while (scanner.hasNextLine())
{
String line = scanner.nextLine();
// Split the line by comma to get FIPS code and county data
String[] parts = line.split(",",2); // Split only into two parts
if (parts.length ==2)
{
String countyFIPSCode = parts[0].trim();
String[] countyData = parts[1].split(",",2); // Split only into two parts
if (countyData.length ==2){
String countyName = countyData[0].trim();
int population = Integer.parseInt(countyData[1].trim());
County county = new County(countyFIPSCode, population, countyName);
countyList.addCounty(county);
} else {
System.out.println("Invalid data format: "+ line);
}
} else
{
System.out.println("Invalid data format: "+ line);
}
}
scanner.close();
} catch (FileNotFoundException e){
e.printStackTrace();
}
}
// Method to process alerts from file
private static void processAlertsFromFile(AlertList alertList, CountyList countyList){
try {
File file = new File("D:\\comp 2\\SecurityCheck\\src\\alerts.txt");
Scanner scanner = new Scanner(file);
while (scanner.hasNextLine())
{
String line = scanner.nextLine();
String[] parts = line.split(",");
try
{
Alert alert = new Alert(parts[0], parts[1], parts[2], parts[3]);
alertList.addAlert(alert);
} catch (ParseException e)
{
System.err.println("Failed to parse alert: "+ e.getMessage());
}
}
scanner.close();
} catch (FileNotFoundException e)
{
e.printStackTrace();
}
}
// Method to output alerts
private static void showOutputInDialog(AlertList alertList, CountyList countyList){
StringBuilder output = new StringBuilder();
for (Alert alert : alertList.getAlerts()){
output.append(alert.generateDescription(countyList)).append("
");
}
JOptionPane.showMessageDialog(null, output.toString(), "Alerts", JOptionPane.INFORMATION_MESSAGE);
}
} Invalid data format: 54107 Wood County, WV
Invalid data format: 54109 Wyoming County, WV
Invalid data format: 55000 WISCONSIN
Invalid data format: 55001 Adams County, WI
Invalid data format: 55003 Ashland County, WI
Invalid data format: 55005 Barron County, WI
Invalid data format: 55007 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Programming The Perl DBI Database Programming With Perl

Authors: Tim Bunce, Alligator Descartes

1st Edition

1565926994, 978-1565926998

More Books

Students also viewed these Databases questions

Question

OSPF is designed as what type of routing protocol?

Answered: 1 week ago

Question

Does IKEv 1 support mobile client vpn connections

Answered: 1 week ago

Question

What is the Definition for Third Normal Form?

Answered: 1 week ago

Question

Provide two examples of a One-To-Many relationship.

Answered: 1 week ago