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 flotilladata.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.basejavalang.NumberFormatException.forInputStringNumberFormatExceptionjava:
at java.basejavalang.Integer.parseIntIntegerjava:
at java.basejavalang.Integer.parseIntIntegerjava:
at FlotillaDriver.loadShipsFlotillaDriverjava:
at FlotillaDriver.mainFlotillaDriverjava:
C:UsersbigbeAppDataLocalNetBeansCacheexecutorsnippetsrunxml:: The following error occurred while executing this line:
C:UsersbigbeAppDataLocalNetBeansCacheexecutorsnippetsrunxml:: Java returned:
BUILD FAILED total time: seconds
Program:
public class FlotillaDriver
private ArrayList shipList;
public FlotillaDriver
shipList new ArrayList;
public static void mainString args
FlotillaDriver driver new FlotillaDriver;
driver.loadShipsflotilladata.csv;
driver.displayMenu;
private void loadShipsString filename
try BufferedReader br new BufferedReadernew FileReaderfilename
String line;
while line brreadLine null
String shipData line.split;
Assume the first element indicates the ship type
Ship ship;
switch shipData
case CG:
ship new CargoShip
shipData shipData Integer.parseIntshipData
Integer.parseIntshipData Integer.parseIntshipData
Integer.parseIntshipData Integer.parseIntshipData
Integer.parseIntshipData;
break;
case YT:
ship new Yacht
shipData shipData Integer.parseIntshipData
Integer.parseIntshipData Integer.parseIntshipData
Integer.parseIntshipData Integer.parseIntshipData
Integer.parseIntshipData Integer.parseIntshipData
Integer.parseIntshipDataInteger.parseIntshipData;
break;
case CR:
ship new CruiseShip
shipData shipData Integer.parseIntshipData
Integer.parseIntshipData Integer.parseIntshipData
Integer.parseIntshipData Integer.parseIntshipData
Integer.parseIntshipData Integer.parseIntshipData;
break;
default:
Default to Ship if type is not recognized
ship new Ship
shipData shipData Integer.parseIntshipData
Integer.parseIntshipData Integer.parseIntshipData
Integer.parseIntshipData;
shipList.addship;
catch IOException e
JOptionPane.showMessageDialognull "Error reading file: egetMessage
"File Read Error", JOptionPane.ERRORMESSAGE;
private void displayMenu
if shipListisEmpty
JOptionPane.showMessageDialognullNo ships loaded.", "Ship Selector", JOptionPane.INFORMATIONMESSAGE;
return;
String options shipList.streammapShip::getNametoArrayString::new;
String menuMessage "Choose a ship to view details or press 'Cancel' to exit";
int response;
do
response JOptionPane.showOptionDialognull menuMessage, "Ship Selector", JOptionPane.DEFAULTOPTION, JOptionPane.PLAINMESSAGE, null, options, options;
if response && response shipList.size
Ship selectedShip shipList.getresponse;
JOptionPane.showMessageDialognull selectedShip.toString "Ship Details", JOptionPane.INFORMATIONMESSAGE;
while response JOptionPane.CLOSEDOPTION;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
