請問我這樣寫有哪些不足,歡迎大神前來指正,謝謝!
import java.util.Scanner;
public class dadaRent {
public static void main(String[] args) {
// TODO Auto-generated method stub
? ? ? ? System.out.println("歡迎使用答答租車系統(tǒng)!");
? ? ? ? System.out.print("您是否要租車:1是 0否\n請選擇:");
? ? ? ? Scanner input=new Scanner(System.in); ? ? ? ?//通過創(chuàng)建Scanner輸入選擇是否租車指令
? ? int num=input.nextInt();
? ?
? ? ? ? if(num==0)
? ? ? ? System.exit(0);
? ? ? ? else
? ? ? ? System.out.println("您可租車的類型及其價目表如下:"); ? ?//顯示所有車型及價格
? ? ? ? ? ? System.out.println("序號 ?汽車名稱 ?租金 ? ? ? ? ? 容量");
? ? ? ? ? ? System.out.println("1. ?奧迪A4 ? 500元/天 ? 載人:4人");
? ? ? ? ? ? System.out.println("2. ?馬自達6 ?400元/天 ? ?載人:4人");
? ? ? ? ? ? System.out.println("3. ?皮卡雪6 ?450元/天 ? ?載人:4人 ?載貨:2噸");
? ? ? ? ? ? System.out.println("4. ?金龍 ? ? ? ? ?800元/天 ? ?載人:20人");
? ? ? ? ? ? System.out.println("5. ?松花江 ? ? ?400元/天 ? ?載貨:4噸");
? ? ? ? ? ? System.out.println("6. ?依維柯 ? ? ?1000元/天 ?載貨:20噸");
? ? ? ? ? ??
? ? ? ? System.out.println("請輸入您要租車的數(shù)量:"); ? ? ?//通過Scanner輸入租車數(shù)量
? ? ? ? int num1=input.nextInt();
? ? ? ? int[] rentday={0,0,0,0,0,0};
? ? ? ? for(int i=1;i<=num1;i++){
? ? ? ? System.out.println("請輸入第"+i+"輛車的序號");
? ? ? ? int num2=input.nextInt();
? ? ? ? rentday[i-1]=num2;
? ? ? ? }
? ? ? ??
? ? ? ? System.out.println("請輸入您要租車的天數(shù):"); ? ? ? ?//通過Scanner輸入租車天數(shù)
? ? ? ? int num3=input.nextInt();
? ? ? ??
? ? ? ? System.out.println("您的賬單:");
? ? ? ? System.out.println("***可載人的車有:"); ? ? ?//統(tǒng)計可載人數(shù)和金額
? ? ? ? int peoplenum=0,cargonum=0,account=0;
? ? ? ? for(int j=0;j<num1;j++){
? ? ? ? if(rentday[j]==1)
? ? ? ? {System.out.print("奧迪A4 ?");peoplenum=peoplenum+4;account=account+500;}
? ? ? ? if(rentday[j]==2)
? ? ? ? {System.out.print("馬自達6 ?");peoplenum=peoplenum+4;account=account+400;}
? ? ? ? if(rentday[j]==3)
? ? ? ? {System.out.print("皮卡雪6 ?");peoplenum=peoplenum+4;account=account+450;}
? ? ? ? if(rentday[j]==4)
? ? ? ? {System.out.print("金龍 ?");peoplenum=peoplenum+20;account=account+800;}
? ? ? ? }
? ? ? ? System.out.println("共載人:"+peoplenum+"人");
? ? ? ??
? ? ? ? System.out.println("***載貨的車有:"); ? ? ?//統(tǒng)計可載貨數(shù)和金額
? ? ? ? for(int k=0;k<num1;k++){
? ? ? ? if(rentday[k]==5)
? ? ? ? {System.out.print("松花江 ?");cargonum=cargonum+4;account=account+400;}
? ? ? ? if(rentday[k]==6)
? ? ? ? {System.out.print("依維柯 ?");cargonum=cargonum+20;account=account+1000;}
? ? ? ? }
? ? ? ? System.out.println("共載貨:"+cargonum+"噸");
? ? ? ??
? ? ? ? System.out.println("***租車總價格:"+account*num3); ? //顯示總金額
? ? ? ? System.out.println("感謝您使用本系統(tǒng),再見!");
? ? ? ? try{}finally{input.close();}
}
}
2015-03-24
這樣寫屬于硬編碼,不太靈活,建議你還是使用面向對象的方式來寫,你可以看看本節(jié)中問答區(qū)置頂?shù)奶?/p>