Basically when I am reading in my file, it does what its supposed to do up until it gets to the "Truck" line. I am getting a NumberFormatException on input String "; 1.5" for the last portion of the truck line. It does the same thing on the axles line for semi. I haven't tested it, but it probably will do the same for engine on the motorcycle portion of the file. I will paste the file I am trying to read from below my code.
Any help would be greatly appreciated. I have looked at this for a while and just cannot figure out what I am doing wrong. If I need to add any other information please let me know! Thanks everyone, in advance!
Joe
import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
public class UseTaxList {
private String taxDistrict;
private Vehicle[] vehicleList;
private String[] excludedRecords;
public UseTaxList() {
taxDistrict = "not yet assigned";
vehicleList = new Vehicle[0];
excludedRecords = new String[0];
}
public void readVehicleFile(String fileIn) throws FileNotFoundException {
vehicleList = new Vehicle[20];
excludedRecords = new String[10];
String owner = "";
String yearMakeModel = "";
double value = 0;
boolean alt = false;
double tons = 0;
double engine = 0;
int axles = 0;
int count = 0;
int offCount = 0;
String fileName = fileIn;
Scanner inFile = new Scanner(new File(fileName));
inFile.useDelimiter(";");
taxDistrict = inFile.nextLine().trim();
String type = "";
while (inFile.hasNext()) {
type = inFile.next().toUpperCase();
char typeChar = type.charAt(0);
switch(typeChar) {
case 'C': //case for Car type
owner = inFile.next().trim();
yearMakeModel = inFile.next().trim();
value = Double.parseDouble(inFile.next().trim());
alt = Boolean.parseBoolean(inFile.nextLine().trim());
Car car = new Car(owner, yearMakeModel, value, alt);
vehicleList[count] = car;
count++;
break;
case 'T': //case for Truck type
owner = inFile.next().trim();
yearMakeModel = inFile.next().trim();
value = Double.parseDouble(inFile.next().trim());
alt = Boolean.parseBoolean(inFile.next().trim());
tons = Double.parseDouble(inFile.nextLine().trim());
Truck truck = new Truck(owner, yearMakeModel, value, alt, tons);
vehicleList[count] = truck;
count++;
break;
case 'S': //case for Semi type
owner = inFile.next().trim();
yearMakeModel = inFile.next().trim();
value = Double.parseDouble(inFile.next().trim());
alt = Boolean.parseBoolean(inFile.next().trim());
tons = Double.parseDouble(inFile.next().trim());
axles = Integer.parseInt(inFile.nextLine().trim());
SemiTractorTrailer semi = new SemiTractorTrailer(owner, yearMakeModel,
value, alt, tons, axles);
vehicleList[count] = semi;
count++;
break;
case 'M': //case for Motorcycle type
owner = inFile.next().trim();
yearMakeModel = inFile.next().trim();
value = Double.parseDouble(inFile.next().trim());
alt = Boolean.parseBoolean(inFile.next().trim());
engine = Double.parseDouble(inFile.nextLine().trim());
Motorcycle moto = new Motorcycle(owner, yearMakeModel, value, alt, engine);
vehicleList[count] = moto;
count++;
break;
default: //other type
owner = inFile.next().trim();
yearMakeModel = inFile.next().trim();
String Offvalue = inFile.next().trim();
String Offalt = inFile.nextLine().trim();
String Offobj = owner + yearMakeModel
+ Offvalue + Offalt;
excludedRecords[offCount] = Offobj;
offCount++;
break;
}
}
inFile.close();
vehicleList = Arrays.copyOf(vehicleList, count);
}
Tax District 52
Car; Jones, Sam; 2017 Honda Accord; 22000; false
car; Jones, Jo; 2017 Honda Accord; 22000; true
race car; Zinc, Zed; 2013 Custom Hot Rod; 61000; false
Car; Smith, Pat; 2015 Mercedes-Benz Coupe; 110000; false
Car; Smith, Jack; 2015 Mercedes-Benz Coupe; 110000; true
Truck; Williams, Jo; 2012 Chevy Silverado; 30000; false; 1.5
Firetruck; Body, Abel; 2015 GMC FE250; 55000; false; 2.5
truck; Williams, Sam; 2010 Chevy Mack; 40000; true; 2.5
Semi; Williams, Pat; 2012 International Big Boy; 45000; false; 5.0; 4
Motorcycle; Brando, Marlon; 1964 Harley-Davidson Sportster; 14000; false; 750