//vehicle
double type[] = {0, 1.0, 1.3, 1.6, 2, 2.4, 2.7};
String carType[] = {"","Compact Car", "Small Car", "Mid Size Car", "Full Size Car", "Truck", "16 Wheeler"};
HashMap <Integer, Double> vehicle = new HashMap<Integer, Double>();
for(int y = 1; y<6; y++)
{
vehicle.put(y, type[y]);
}
HashMap <Integer, String> CarName = new HashMap<>();
for(int a = 1; a<6; a++)
{
CarName.put(a, carType[a]);
}
/**
* Now begin to read the file and reference the tables.
*/
int gate1, vehicle1, toll1, factor, cost;
String car;
System.out.println(EasyFormat.format("Car Type", 0)+EasyFormat.format("Base Toll", 15)+EasyFormat.format("Factor", 22)+EasyFormat.format("Cost",30));
while(file.hasNext())
{
gate1 = file.nextInt();
vehicle1 = file.nextInt();
factor = (Double) vehicle.get(vehicle1);
}
答案 0 :(得分:4)
下面:
int factor; //other variables as well
//more code...
while(file.hasNext()) {
//more code...
factor = (Double) vehicle.get(vehicle1);
}
factor
是int
类型,您正试图向其Double
发送邮件。
将factor
声明为double
或使用Double#intValue
。我希望将factor
声明为double
并让拆箱工作。