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

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

關于租車的實現,結構上有什么問題,求指導

關于租車的實現,結構上有什么問題,求指導

攻城獅1994 2016-08-29 18:42:16
package?muke.stu.one; import?java.util.Scanner; import?muke.stu.one.entity.Car; import?muke.stu.one.entity.Coatch; import?muke.stu.one.entity.Pika; import?muke.stu.one.entity.Truck; public?class?rentCar?{ ????static?Scanner?in?=?new?Scanner(System.in); ????public?static?void?main(String[]?args)?{ ????????Boolean?isRentCar?=?false; ????????int?carNum?=?0; ????????String?rentInformation?=?null; ????????Car[]?carInit?=?{new?Pika("皮卡",2,6,1200),?new?Truck("大貨車",20,800),new?Coatch("客車",20,1000),new?Pika("破皮卡",3,5,800), ????????????????????????new?Coatch("破客車",25,1000)}; ???????? ????????System.out.println("是否需要租車:1.是?????2.否"); ????????int?rentCar?=?in.nextInt(); ????????if(rentCar?==?1){ ????????????isRentCar?=?true; ????????} ????????if(isRentCar){ ????????????System.out.println("租用幾輛車:"); ????????????carNum?=?in.nextInt(); ????????????rentInformation?=?rent(carNum,carInit); ????????????System.out.println("您的租車信息:"+"\n"+rentInformation); ????????} ????????System.out.println("謝謝使用"); ????} ????//租車界面 ????public?static?String?rent(int?carNum,Car[]?carArray){ ????????String?rentInformation?=?null; ????????int?carID; ????????double?cost?=0.0; ????????int??people=0; ????????int?capacity=0; ????????int?days?=0; ????????String?addPeople?=""; ????????String?addCapacity=""; ????????//展示車輛信息 ????????System.out.println("序號?\t類型?\t容量?\t價格(元/天)"); ????????for(int?i=0;i<carArray.length;i++){ ????????????System.out.println(i+1+"\t"+carArray[i].getType() ????????????????????????????+"\t"+carArray[i].getContent()+"\t"+carArray[i].getPrice()); ????????} ????????//獲取選擇車輛 ????????for(int?m=0;m<carNum;m++){ ????????????System.out.println("請輸入您需要車輛序號:"); ????????????carID=in.nextInt(); ????????????Car?carRent?=carArray[carID-1]; ????????????if(carRent?instanceof?Pika){ ????????????????cost?+=?carRent.getPrice(); ????????????????people?+=?((Pika)?carRent).getManned(); ????????????????capacity?+=?((Pika)?carRent).getCapacity(); ????????????????addPeople?+=?carRent.getType()+"\t"; ????????????????addCapacity?+=?carRent.getType()+"\t"; ????????????}else?if(carRent?instanceof?Truck){ ????????????????cost?+=?carRent.getPrice(); ????????????????capacity?+=?((Truck)?carRent).getCapacity(); ????????????????addCapacity?+=?carRent.getType()+"\t"; ????????????}else{ ????????????????cost?+=?carRent.getPrice(); ????????????????people?+=?((Coatch)?carRent).getManned(); ????????????????addPeople?+=?carRent.getType()+"\t"; ????????????} ????????} ????????System.out.println("請輸入您需要租借的天數"); ????????days=?in.nextInt(); ????????cost?=?cost*days; ????????//格式化租車信息 ????????rentInformation?="您租用載人的車有:"+"\n"+addPeople+"共載人:"+people+"\n"? ????????????????+"您租用貨物的車有:"+"\n"+addCapacity+"共載貨物:"+capacity+"\n" ????????????????+"您租車:"+days+"天"+"\t"+"共花費:"+cost+"元"; ????????return?rentInformation; ????} } package?muke.stu.one.entity; public?class?Car?{ ????//名字,類型 ????private?String?type; ????//價錢 ????private?double?price; ????//容量 ????private?String?content; ????public?String?getContent()?{ ????????return?content; ????} ????public?void?setContent(String?content)?{ ????????this.content?=?content; ????} ????public?String?getType()?{ ????????return?type; ????} ????public?void?setType(String?type)?{ ????????this.type?=?type; ????} ????public?double?getPrice()?{ ????????return?price; ????} ????public?void?setPrice(double?price)?{ ????????this.price?=?price; ????} ???? } package?muke.stu.one.entity; import?muke.stu.one.serivce.transportGoods; import?muke.stu.one.serivce.transportPeople; public?class?Pika?extends?Car?implements?transportGoods,transportPeople{ ????private?int?capacity; ????private?int?manned; ???? ????public?int?getCapacity()?{ ????????return?capacity; ????} ????public?void?setCapacity(int?capacity)?{ ????????this.capacity?=?capacity; ????} ????public?int?getManned()?{ ????????return?manned; ????} ????public?void?setManned(int?manned)?{ ????????this.manned?=?manned; ????} ????public?Pika(){ ????????super(); ????} ????public?Pika(String?type,int?manned,int?capacity,double?price){ ????????this.setType(type); ????????this.setCapacity(capacity); ????????this.setManned(manned); ????????this.setPrice(price); ????????this.setContent(transportPeople()+transportGoods()); ????} ???? ???? ????@Override ????public?String?transportPeople()?{ ????????String?transportPeople?="載人量:"+this.getManned(); ????????return?transportPeople; ???????? ????} ????@Override ????public?String?transportGoods()?{ ????????String?transportGoods="載貨量:"+this.getCapacity(); ????????return?transportGoods; ????} ???? } package?muke.stu.one.entity; import?muke.stu.one.serivce.transportPeople; public?class?Coatch?extends?Car?implements?transportPeople{ ????private?int?manned; ????public?int?getManned()?{ ????????return?manned; ????} ????public?void?setManned(int?manned)?{ ????????this.manned?=?manned; ????} ????public?Coatch(){ ????????super(); ????} ????public?Coatch(String?type,int?manned,double?price){ ????????this.setType(type); ????????this.setManned(manned); ????????this.setPrice(price); ????????this.setContent(transportPeople()); ????} ????@Override ????public?String?transportPeople()?{ ????????String?transportPeople?="載人量:"+this.getManned(); ????????return?transportPeople; ???????? ????} } package?muke.stu.one.entity; import?muke.stu.one.serivce.transportGoods; public?class?Truck?extends?Car?implements?transportGoods{ ????private?int?capacity; ????public?int?getCapacity()?{ ????????return?capacity; ????} ????public?void?setCapacity(int?capacity)?{ ????????this.capacity?=?capacity; ????} ????public?Truck(){ ????????super(); ????} ????public?Truck(String?type,int?capacity,double?price){ ????????this.setType(type); ????????this.setCapacity(capacity); ????????this.setPrice(price); ????????this.setContent(transportGoods()); ????} ????@Override ????public?String?transportGoods()?{ ????????String?transportGoods="載貨量:"+this.getCapacity(); ????????return?transportGoods; ????} ???? } package?muke.stu.one.serivce; public?interface?transportGoods?{ ????public?String?transportGoods(); } package?muke.stu.one.serivce; public?interface?transportPeople?{ ????public??String?transportPeople(); }
查看完整描述

1 回答

?
qq_晝綻_0

TA貢獻82條經驗 獲得超17個贊

哪里出錯了,這么多怎么看,

查看完整回答
反對 回復 2016-08-29
  • 攻城獅1994
    攻城獅1994
    沒錯啊,但是接口到底用來做什么呢?只是作為不同功能的輸出么?
  • 1 回答
  • 1 關注
  • 1269 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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