不是有個載重的車和載人的車的需求嗎,怎么做區分
我的代碼如下:
package?com.exerciseTWO;
import?java.util.Scanner;
public?class?Test?{
????public??void?zuche()?{
????????Scanner?input?=?new?Scanner(System.in);
????????int?p?=?input.nextInt();
????????if(p==1){
????????????zhuliucheng();
????????}else?if(p?==?2){
????????????System.out.println("感謝您使用大大租車系統~");
????????}else{
????????????System.out.println("您輸入的有誤,請重新輸入");
????????????System.out.println("您是否需要租車:1、是"?+?"\t"?+?"0、否");
????????????zuche();
????????}
????}
????public?void?zhuliucheng(){
????????Vehicle?cars?[]?=?{
????????????????new?PassengerCar(1,"奧迪A4",500,4),
????????????????new?PassengerCar(2,"馬自達6",400,4),
????????????????new?PickUpCar(3,"皮卡雪6",450,4,2),
????????????????new?PassengerCar(4,"金龍",800,20),
????????????????new?TrunkCar(5,"松花江",400,4),
????????????????new?TrunkCar(6,"依維柯",1000,20)
????????};
//輸出車輛的信息列表
????????????System.out.println("您可組車的類型及其價目表:\n序號??汽車名稱??租金?????????容量"?);
????????????for(int?i=0;i<cars.length;i++)?{
????????????????cars[i].print();
????????????}
????????????//輸出租車數量
????????????System.out.println("請輸入你想要租車的數量");
????????????Scanner?carsNumInput=?new?Scanner(System.in);
????????????int?carsNum=?carsNumInput.nextInt();//輸入租車數量
???????????int?carsNumArraylist[]?=?new?int[carsNum];
???????????int?totalPassenger?=?0;//?總人數
???????????int?totalTrunk=0;//總重量
???????????double?totalPrice=0;//總價格
????????????if(carsNum>0){
????????????????for(int?o=0;o<carsNum;o++){
????????????????????System.out.println("請輸入您需要的第"+(o+1)+"輛車的號碼(序號)");
????????????????????int??id=?carsNumInput.nextInt();//輸入了每個序號
????????????????????totalPassenger=??totalPassenger?+cars[id-1].PassengerNum;
????????????????????totalPrice?=?totalPrice?+?cars[id-1].CarPrice;
????????????????????totalTrunk?=?totalTrunk?+?cars[id-1].TrunkNum;
????????????????????carsNumArraylist[o]?=?id;
????????????????}
????????????????System.out.println("請輸入你需要租用的天數");
????????????????int?day?=?carsNumInput.nextInt();
????????????????System.out.println("*******可載人的車有:");
????????????????for(int?i?=0;i<carsNumArraylist.length;i++){
????????????????????System.out.println(cars[carsNumArraylist[i]-1].CarName?);
????????????????}
????????????????System.out.println("總載人:"+?totalPassenger);
????????????????System.out.println("*******可載貨的車有:");
????????????????for(int?i?=?0;i<carsNumArraylist.length;i++)?{
????????????????????System.out.println(cars[carsNumArraylist[i]-1].CarName);
????????????????}
????????????????System.out.println("總載重:"+totalTrunk);
????????????????totalPrice?=totalPrice*day;
????????????????System.out.println("*******租車總價格:"+"\n"?+?totalPrice?+"元");
????????????????System.out.println("進入正確流程");
????????????}else{
????????????????System.out.println("輸入編號有誤直接退出系統");
????????????}
????????}
????public?static?void?main(String[]?args)?{
????????System.out.println("歡迎使用大大租車系統!");
????????System.out.println("請問您是否需要租車?"+"\t"?+?"1.是"?+"\t"+"2.否");
????????Test?demoMain?=?new?Test();
????????demoMain.zuche();
????}
}
2019-10-31
加條件判斷