我最后輸出的總價格什么的都是0,為什么。
package com.imooc;
import java.util.*;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
List<car> cars = new ArrayList<car>();
? ? ? ? ?System.out.println("歡迎來到達達租車系統(tǒng)");
? ? ? ? ?System.out.println("你是否要租車 : 1 是 2 否");
? ? ? ? ?
? ? ? ? ?car aodi=new aodi();
? ? ? ? ?cars.add(aodi);
? ? ? ? ?car jinlong=new jinlong();
? ? ? ? ?cars.add(jinlong);
? ? ? ? ?car mazida=new mazida();
? ? ? ? ?cars.add(mazida);
? ? ? ? ?car pikaxue=new pikaxue();
? ? ? ? ?cars.add(pikaxue);
? ? ? ? ?car song=new song();
? ? ? ? ?cars.add(song);
? ? ? ? ?car yiweike=new yiweike();
? ? ? ? ?cars.add(yiweike);
? ? ? ??
? ? ? ? ?Scanner k = new Scanner(System.in);
? ? ? ? ?int num=k.nextInt();
? ??
? ? ? ? ?if(num==1){
? ? ? ? System.out.println("你可租車得類型及價格表:"+"\n"+"序號"+"\t"+"汽車名稱"+"\t"+"租金"+"\t"+"載人"+"\t"+"容量");
? ? ? ? aodi.Car(1);
? ? ? ? jinlong.Car(2);
? ? ? ? mazida.Car(3);
? ? ? ? pikaxue.Car(4);
? ? ? ? song.Car(5);
? ? ? ? yiweike.Car(6);
? ? ? ? System.out.println("請輸入你要的汽車數(shù)量:");
? ? ? ? Scanner amount=new Scanner(System.in);
? ? ? ? int b=amount.nextInt();
? ? ? ? int c;
? ? ? ? int allmanned=0;
? ? ? ? int allcargo=0;
? ? ? ? int allrent=0;
? ? ? ? String person="";
? ? ? ? String Cars="";
? ? ? ? for(int i=1;i<=b;i++){
? ? ? ? do{
? ? ? ? System.out.println("請輸入第"+i+"輛車的序號");
? ? ? ? Scanner k2=new Scanner(System.in);
? ? ? ? c=k2.nextInt();
? ? ? ? }while(c<1||c>6);
? ? ? ?
? ? ? ?
? ? ? ? car cc=cars.get(c-1);
? ? ? ? if(cc.manned>0){
? ? ? ? allmanned+=cc.manned;
? ? ? ? person+=cc.name+"";
? ? ? ? }
? ? ? ? if(cc.cargo>0){
? ? ? ? allcargo+=cc.cargo;
? ? ? ? Cars+=cc.name+""; ? ? ? ?
? ? ? ? }
? ? ? ? allrent+=cc.rent;
? ? ? ? System.out.println("請輸入要租用的天數(shù)");
? ? ? ? Scanner k3=new Scanner(System.in);
? ? ? ? int t=k3.nextInt();
? ? ? ? allrent*=t;
? ? ? ? System.out.println("你的賬單:"+"\n"+"可載人的車有:"+person+"\t"+"共載客:"+allmanned);
? ? ? ? System.out.println("可載貨的車有:"+Cars+"共載貨"+allcargo);
? ? ? ? System.out.println("總租金為:"+allrent);
? ? ? ? }
? ? ? ? ?}
? ? ? ? ?
}
}
2016-07-25
有參考成分。從car cc=cars.get(c-1);開始沒有跳入if語句中。