Question: Could someone please debug this porgram at first the program couldnt see my data file flotilla _ data.csv so I put in the correct name

Could someone please debug this porgram at first the program couldnt see my data file flotilla_data.csv so I put in the correct name for the file but that caused multiple exception errors can someone fix this?
Error:Exception in thread "main" java.lang.NumberFormatException: For input string: "India"
at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:67)
at java.base/java.lang.Integer.parseInt(Integer.java:665)
at java.base/java.lang.Integer.parseInt(Integer.java:781)
at FlotillaDriver.loadShips(FlotillaDriver.java:38)
at FlotillaDriver.main(FlotillaDriver.java:23)
C:\Users\bigbe\AppData\Local\NetBeans\Cache\18\executor-snippets\run.xml:111: The following error occurred while executing this line:
C:\Users\bigbe\AppData\Local\NetBeans\Cache\18\executor-snippets\run.xml:68: Java returned: 1
BUILD FAILED (total time: 0 seconds)
Program:
public class FlotillaDriver {
private ArrayList shipList;
public FlotillaDriver(){
shipList = new ArrayList<>();
}
public static void main(String[] args){
FlotillaDriver driver = new FlotillaDriver();
driver.loadShips("flotilla_data.csv");
driver.displayMenu();
}
private void loadShips(String filename){
try (BufferedReader br = new BufferedReader(new FileReader(filename))){
String line;
while ((line = br.readLine())!= null){
String[] shipData = line.split(",");
// Assume the first element indicates the ship type
Ship ship;
switch (shipData[0]){
case "CG":
ship = new CargoShip(
shipData[1], shipData[2], Integer.parseInt(shipData[3]),
Integer.parseInt(shipData[4]), Integer.parseInt(shipData[5]),
Integer.parseInt(shipData[6]), Integer.parseInt(shipData[7]),
Integer.parseInt(shipData[8]));
break;
case "YT":
ship = new Yacht(
shipData[1], shipData[2], Integer.parseInt(shipData[3]),
Integer.parseInt(shipData[4]), Integer.parseInt(shipData[5]),
Integer.parseInt(shipData[6]), Integer.parseInt(shipData[7]),
Integer.parseInt(shipData[8]), Integer.parseInt(shipData[9]),
Integer.parseInt(shipData[10]),Integer.parseInt(shipData[11]));
break;
case "CR":
ship = new CruiseShip(
shipData[1], shipData[2], Integer.parseInt(shipData[3]),
Integer.parseInt(shipData[4]), Integer.parseInt(shipData[5]),
Integer.parseInt(shipData[6]), Integer.parseInt(shipData[7]),
Integer.parseInt(shipData[8]), Integer.parseInt(shipData[9]));
break;
default:
// Default to Ship if type is not recognized
ship = new Ship(
shipData[1], shipData[2], Integer.parseInt(shipData[3]),
Integer.parseInt(shipData[4]), Integer.parseInt(shipData[5]),
Integer.parseInt(shipData[6]));
}
shipList.add(ship);
}
} catch (IOException e){
JOptionPane.showMessageDialog(null, "Error reading file: "+ e.getMessage(),
"File Read Error", JOptionPane.ERROR_MESSAGE);
}
}
private void displayMenu(){
if (shipList.isEmpty()){
JOptionPane.showMessageDialog(null,"No ships loaded.", "Ship Selector", JOptionPane.INFORMATION_MESSAGE);
return;
}
String[] options = shipList.stream().map(Ship::getName).toArray(String[]::new);
String menuMessage = "Choose a ship to view details or press 'Cancel' to exit";
int response;
do {
response = JOptionPane.showOptionDialog(null, menuMessage, "Ship Selector", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
if (response >=0 && response < shipList.size()){
Ship selectedShip = shipList.get(response);
JOptionPane.showMessageDialog(null, selectedShip.toString(), "Ship Details", JOptionPane.INFORMATION_MESSAGE);
}
} while (response != JOptionPane.CLOSED_OPTION);
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!