為什么綜合練習(xí)的名字始終是null呢?
package com.imooc.test7;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
//創(chuàng)建車輛信息
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數(shù)組
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("謝謝你的光臨,再見!");
}
}
//租車數(shù)量
System.out.println("請輸入你需要租車的數(shù)量:");
int carnum = in.nextInt();
Car[] choicecar = new Car[carnum]; //將選擇的序號存入數(shù)組
for(int i = 0;i < carnum ;i++){
System.out.println("請輸入第"+ (i+1) +"輛車的序號");
int num = in.nextInt();
choicecar[i] = car[num-1];
}
//租車天數(shù)
System.out.println("請輸入租車天數(shù)");
int rentday = in.nextInt();
//計算并顯示賬單
System.out.println("*********************您的賬單:**********************");
int allmoney = 0;//總的租金
System.out.println("您總共要租借"+rentday+"天");
//計算總載客數(shù)載貨量
int allPesCar = 0; ?//總載人數(shù)
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("謝謝光臨租車地帶,下次再見!");
}
}
2016-03-19
2016-03-18
可以把報錯信息貼上來么?