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

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

這是我做的一個簡單的控制臺程序租車系統,請大神們指點一下,一起交流。

這是我做的一個簡單的控制臺程序租車系統,請大神們指點一下,一起交流。

linbingfeng 2016-03-13 16:24:17
//測試類 package?com.System.show; import?com.leasesystem.car.*; import?java.util.Scanner; public?class?Demo?{ public?static?void?main(String[]?args)?{ int?sum?=?0; int?peopleSum?=?0; int?goodsSum?=?0; System.out.println("您是否租車?(1:是/0:不是)"); Scanner?scanner?=?new?Scanner(System.in); String??num1?=?scanner.next(); if?("1".equals(num1))?{ System.out.println("序號"+"?"+"類型"+"?"+"價格"+"?"+"容量"); for(int?i?=?1;i<7;i++){ Vehicle?car?=?Demo.showCar(i); System.out.println(car.getId()+"?"+car.getType()+"?"+car.getPrice()+"?"+car.getCapacity()+car.getCapaUnit()); } for?(boolean?bool?=?true;bool?==?true;)?{ System.out.println("請輸入要租的車型(0:選車結束):"); String??num2?=?scanner.next(); int?num2_1?=?Integer.parseInt(num2); if("0".equals(num2)){ bool?=?false; }else?if(num2_1?>6){ System.out.println("輸入錯誤!重新輸入"); }else{ Vehicle?car?=?Demo.showCar(num2_1); sum?+=?car.getPrice(); if?(car.getCapaUnit().equals("噸/輛"))?{ goodsSum?+=?car.getCapacity(); }else{ peopleSum?+=?car.getCapacity(); } } } }?else?{ System.out.println("謝謝光臨"); } System.out.println("租借清單:"); System.out.println("總金額:"+sum); System.out.println("總載人量:"+peopleSum); System.out.println("總載貨量:"+goodsSum); scanner.close(); } private?static?Vehicle?showCar(int?i)?{ switch?(i)?{ case?1: { Vehicle?car?=?new?SalooCar(); return?car; } case?2: { Vehicle?car?=?new?StandardCar(); return?car; } case?3: { Vehicle?car?=?new?Bus(); return?car; } case?4: { Vehicle?car?=?new?Truck(); return?car; } case?5: { Vehicle?car?=?new?HeavyTruck(); return?car; } case?6: { Vehicle?car?=?new?Pickup(); return?car; } default: { Vehicle?car?=?new?StandardCar(); return?car; } } } } //抽象car父類 package?com.leasesystem.car; public?abstract?class?Vehicle?{ ?int?id; ?String?type; ?int?price; ?int?capacity; ?String?capaUnit; ? public?int?getId()?{ return?id; } public?void?setId(int?id)?{ this.id?=?id; } public?String?getType()?{ return?type; } public?void?setType(String?type)?{ this.type?=?type; } public?int?getPrice()?{ return?price; } public?void?setPrice(int?price)?{ this.price?=?price; } public?int?getCapacity()?{ return?capacity; } public?void?setCapacity(int?capacity)?{ this.capacity?=?capacity; } public?String?getCapaUnit()?{ return?capaUnit; } public?void?setCapaUnit(String?capaUnit)?{ this.capaUnit?=?capaUnit; } } //各種類型的車類 //豪華轎車類 package?com.leasesystem.car; public?class?SalooCar?extends?Vehicle?{ public?SalooCar(){ this.id?=?1; this.type?=?"豪華轎車"; this.price?=?500; this.capacity?=?6; this.capaUnit?=?"人/輛"; } } //普通汽車類 package?com.leasesystem.car; public?class?StandardCar?extends?Vehicle?{ public?StandardCar()?{ this.id?=?2; this.type?=?"普通汽車"; this.price?=?350; this.capacity?=?4; this.capaUnit?=?"人/輛"; } } //客車類 package?com.leasesystem.car; public?class?Bus?extends?Vehicle?{ public?Bus(){ this.id?=?3; this.type?=?"客車"; this.price?=?1000; this.capacity?=?50; this.capaUnit?=?"人/輛"; } } //貨車類 package?com.leasesystem.car; public?class?Truck?extends?Vehicle?{ public?Truck()?{ this.id?=?4; this.type?=?"卡車"; this.price?=?1000; this.capacity?=?5; this.capaUnit?=?"噸/輛"; } } //重型貨車類 package?com.leasesystem.car; public?class?HeavyTruck?extends?Vehicle?{ public?HeavyTruck()?{ this.id?=?5; this.type?=?"重型貨車"; this.price?=?3000; this.capacity?=?20; this.capaUnit?=?"噸/輛"; } } //別克車類 package?com.leasesystem.car; public?class?Pickup?extends?Vehicle?{ public?Pickup()?{ this.id?=?6; this.type?=?"皮卡車"; this.price?=?600; this.capacity?=?1; this.capaUnit?=?"噸/輛"; } }
查看完整描述

1 回答

?
幫秋

TA貢獻125條經驗 獲得超79個贊

好好,寫的很好

查看完整回答
反對 回復 2016-03-14
  • 1 回答
  • 0 關注
  • 1810 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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