为什么综合练习的名字始终是null呢?
package com.imooc.test7;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
//创建车辆信息
Car[] car = {new PessagerCar("奥迪A4 ", 500, 4),new CargoCar("松花江", 400, 4),new PukiCar("皮卡雪6", 450, 4,2)};
System.out.println("欢迎来到租车地带!");
System.out.println("请问是否需要租车:1是 2否");
//显示租车信息
Scanner in = new Scanner(System.in);
int choice = in.nextInt();
while(choice != 2 || choice !=1){
//如果输入错误,非0/1,则重新输入
if(choice == 1){
System.out.println("你可租车的类型及价目表:");
System.out.println(""+"序号" + "\t" + "汽车名称" + "\t" + "租金" + "\t" + "容量");
int i =0;
for(Car curCar:car){ //定义一个curCar对象遍历car数组
i++;
if(curCar instanceof PessagerCar){
System.out.println("" + i + "\t" + curCar.getName() + "\t" + curCar.getRent() + "元/辆"+ "\t"+ ((PessagerCar) curCar).getManned() + "人");
//car[i].show(); //显示租车信息及序号
}
if(curCar instanceof CargoCar){
System.out.println("" + i + "\t" + curCar.getName() + "\t" + curCar.getRent() + "元/辆" +"\t"+ ((CargoCar) curCar).getCargo() + "吨");
}
if(curCar instanceof PukiCar){
System.out.println("" + i + "\t" + curCar.getName() + "\t" + curCar.getRent() + "元/辆" +"\t"+ ((PukiCar) curCar).getManned() + "人" + ((PukiCar) curCar).getCargo() + "吨");
}
}
break;
}else{
System.out.println("谢谢你的光临,再见!");
}
}
//租车数量
System.out.println("请输入你需要租车的数量:");
int carnum = in.nextInt();
Car[] choicecar = new Car[carnum]; //将选择的序号存入数组
for(int i = 0;i < carnum ;i++){
System.out.println("请输入第"+ (i+1) +"辆车的序号");
int num = in.nextInt();
choicecar[i] = car[num-1];
}
//租车天数
System.out.println("请输入租车天数");
int rentday = in.nextInt();
//计算并显示账单
System.out.println("*********************您的账单:**********************");
int allmoney = 0;//总的租金
System.out.println("您总共要租借"+rentday+"天");
//计算总载客数载货量
int allPesCar = 0; //总载人数
int allCargo = 0; //总载货量
for(int i=0; i<choicecar.length ; i++){
if(choicecar[i] instanceof PessagerCar){
allPesCar += ((PessagerCar) choicecar[i]).getManned();
allmoney += ((PessagerCar) choicecar[i]).getRent();
}
if(choicecar[i] instanceof CargoCar){
allCargo += ((CargoCar) choicecar[i]).getCargo();
allmoney += ((CargoCar) choicecar[i]).getRent();
}
if(choicecar[i] instanceof PukiCar){
allPesCar += ((PukiCar) choicecar[i]).getManned();
allCargo +=((PukiCar)choicecar[i]).getCargo();
allmoney += ((PessagerCar) choicecar[i]).getRent();
allmoney += ((CargoCar) choicecar[i]).getRent();
}
}
//输出清单
System.out.println("您所要租借的总载客量为: " + allPesCar + "人\t" + "总载货量为:" + allCargo + "吨");
int totalPrice = allmoney*rentday; //总价
System.out.println("您总共需要支付: " + totalPrice + " 元");
System.out.println("谢谢光临租车地带,下次再见!");
}
}