亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

綜合練習 和老師的輸出完全一致。

綜合練習 和老師的輸出完全一致。

_該用戶已注銷 2017-07-14 12:54:23
package?wang; public?class?Car?{ protected??String?carName; protected?int?rentMoney; protected?int?pessengersCapacity; protected?int?cargoCapacity; } package?wang; public?class?Passengercar?extends?Car?{ protected?Passengercar(String?carName,int?rentMoney,int?pessengersCapacity){ this.carName?=?carName; this.rentMoney?=?rentMoney; this.pessengersCapacity?=?pessengersCapacity; } @Override public?String?toString()?{ return??"?\t"+carName?+?"\t"?+?rentMoney?+?"元/天?\t載人:"+?pessengersCapacity+"人"?; } } package?wang; public?class?Truck?extends?Car?{ protected?Truck(String?carName,int?rentMoney,int?cargoCapacity){ this.carName?=?carName; this.rentMoney?=?rentMoney; this.cargoCapacity?=?cargoCapacity; } public?String?toString()?{ return??"?\t"+carName?+?"\t"?+?rentMoney?+?"元/天?\t載貨:"+cargoCapacity+"噸"; } } package?wang; public?class?Pickup?extends?Car?{ protected?Pickup(String?carName,int?rentMoney,int?pessengersCapacity,int?cargoCapacity){ this.carName?=?carName; this.rentMoney?=?rentMoney; this.pessengersCapacity?=?pessengersCapacity; this.cargoCapacity?=?cargoCapacity; } public?String?toString()?{ return??"?\t"+carName?+?"\t"?+?rentMoney?+?"元/天?\t載人:"+?pessengersCapacity+"人載貨:"+cargoCapacity+"噸"; } } package?wang; import?java.util.*; public?class?initial?{ public?static?void?main(String[]?args)?{ //?TODO?Auto-generated?method?stub Car?car[]?=?{?new?Passengercar("奧迪A4",500,4),new?Passengercar("馬自達6",400,4), ??new?Pickup("皮卡雪6",450,4,2),new?Passengercar("金龍",800,20), ??new?Truck("松花江",400,4),new?Truck("依維柯",1000,20) }; System.out.println("歡迎使用答答租車系統:"); System.out.println("你是否要租車:1是?0否"); Scanner?input?=?new?Scanner(System.in); if(input.nextInt()?==?1){?????//判斷是否要進入系統 System.out.println("你可租車的類型及價目表:"); System.out.println("序號?\t汽車名稱\t租金?????\t容量"); for?(int?i?=?0;?i?<?car.length;?i++)?{??//列出所有車型 System.out.print(i+1+"."); System.out.println(car[i]); } System.out.println("請輸入你要租車的數量:"); int?carRentNum?=?input.nextInt();//租車數量 int?carArr[]?=?new?int?[carRentNum];?//獲得租車序號并存入數組 for(int?i?=0;?i<carRentNum;i++){ System.out.println("請輸入第"+(i+1)+"輛車的序號:"); carArr[i]?=?input.nextInt(); } System.out.println("請輸入租車天數:"); int?rentDays?=?input.nextInt();//租車天數 System.out.println("您的賬單:"); System.out.println("***可載人的車有:"); int?totalPessengerCapacity?=0;//總載人數 for(int?i?=0;i<carRentNum;i++){ if(car[carArr[i]-1].pessengersCapacity?>?0){ totalPessengerCapacity?+=?car[carArr[i]-1].pessengersCapacity; System.out.print(car[carArr[i]-1].carName+"??"); } } System.out.println("共載人:"+totalPessengerCapacity+"人"); System.out.println("***可載貨的車有:"); float?totalCargoCapacity?=0f;//總載貨量 for(int?i?=0;i<carRentNum;i++){ if(car[carArr[i]-1].cargoCapacity?>?0){ totalCargoCapacity?+=?car[carArr[i]-1].cargoCapacity?; System.out.print(car[carArr[i]-1].carName+"??"); } } System.out.println("共載貨:"+totalCargoCapacity+"噸"); System.out.print("***租車總價格:"); float?totalRentMoney?=?0f;?//總租金 for(int?i?=0;i<carRentNum;i++){ totalRentMoney?+=?car[carArr[i]-1].rentMoney?*?rentDays; } System.out.println(totalRentMoney+"元"); } else System.out.println("謝謝使用答答租車系統,再見!"); } }
查看完整描述

2 回答

?
MR帽子先生

TA貢獻245條經驗 獲得超106個贊


你好,有什么可以幫你的?

查看完整回答
反對 回復 2017-07-16
  • 2 回答
  • 0 關注
  • 1167 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號