基本上当我在我的文件中阅读时,它会做它应该做的事情,直到它到达"卡车"线。我在输入String&#34 ;;上得到一个NumberFormatException。 1.5"对于卡车线的最后部分。它在半轴的轴线上做同样的事情。我还没有测试过它,但它可能会对文件摩托车部分的引擎做同样的事情。我将从我的代码下面粘贴我想要阅读的文件。
非常感谢任何帮助。我已经看了一会儿,只是无法弄清楚我做错了什么。如果我需要添加任何其他信息,请告诉我!提前谢谢大家!
乔
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);
}
税区52
汽车;琼斯,山姆; 2017本田雅阁; 22000;假
车;琼斯,乔; 2017本田雅阁; 22000;真
赛车;锌,Zed; 2013年定制热棒; 61000;假汽车;史密斯,帕特; 2015梅赛德斯 - 奔驰Coupe; 110000;假
汽车;史密斯,杰克; 2015梅赛德斯 - 奔驰Coupe; 110000;真
卡车;威廉姆斯,乔; 2012 Chevy Silverado; 30000;假; 1.5
救火车;身体,亚伯; 2015 GMC FE250; 55000;假; 2.5
卡车;威廉姆斯,山姆; 2010 Chevy Mack; 40000;真正; 2.5
半;威廉姆斯,帕特; 2012年国际大男孩; 45000;假; 5.0; 4
摩托车;白兰度,马龙; 1964年Harley-Davidson Sportster; 14000;假; 750