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

為了賬號安全,請及時綁定郵箱和手機立即綁定

交作業:嗒嗒租車系統

package?com.imooc;
public?class?Che?{
?private?String?carName;
?private?int?carPrice;
?private?int?carPCapacity;
?private?int?carGCapacity;
?
?public?String?getCarName()?{
??return?carName;
?}
?public?void?setCarName(String?carName)?{
??this.carName?=?carName;
?}
?public?int?getCarPrice()?{
??return?carPrice;
?}
?public?void?setCarPrice(int?carPrice)?{
??this.carPrice?=?carPrice;
?}
?public?int?getCarPCapacity()?{
??return?carPCapacity;
?}
?public?void?setCarPCapacity(int?carPCapacity)?{
??this.carPCapacity?=?carPCapacity;
?}
?public?int?getCarGCapacity()?{
??return?carGCapacity;
?}
?public?void?setCarGCapacity(int?carGCapacity)?{
??this.carGCapacity?=?carGCapacity;
?}
}
package?com.imooc;
public?class?HuoChe?extends?Che?{
?private?int?carPCapacity;
?
?public?HuoChe(String?carName,?int?carPrice?,int?carGCapacity)?{
??this.setCarName(carName);
??this.setCarPrice(carPrice);
??this.setCarPCapacity();
??this.setCarGCapacity(carGCapacity);
?}
?public?int?getCarPCapacity()?{
??return?carPCapacity;
?}
?public?void?setCarPCapacity()?{
??this.carPCapacity?=?0;
?}
}
package?com.imooc;
public?class?KeChe?extends?Che?{
?private?int?carGCapacity;
?
?public?KeChe(String?carName,?int?carPrice,?int?carPCapacity)?{
??this.setCarName(carName);
??this.setCarPrice(carPrice);
??this.setCarPCapacity(carPCapacity);
??this.setCarGCapacity();
?}
?public?int?getCarGCapacity()?{
??return?carGCapacity;
?}
?public?void?setCarGCapacity()?{
??this.carGCapacity?=?0;
?}
}
package?com.imooc;
public?class?PiKa?extends?Che?{
?
?public?PiKa(String?carName,?int?carPrice,?int?carPCapacity,?int?carGCapacity)?{
??this.setCarName(carName);
??this.setCarPrice(carPrice);
??this.setCarPCapacity(carPCapacity);
??this.setCarGCapacity(carGCapacity);
?}
}
package?com.imooc;
import?java.util.Scanner;
public?class?Test?{
?
?static?KeChe?k1?=?new?KeChe("奧迪A4",?500,?4);
?static?KeChe?k2?=?new?KeChe("馬自達6",?400,?4);
?static?KeChe?k3?=?new?KeChe("金龍",?800,?20);
?static?HuoChe?h1?=?new?HuoChe("松花江",?400,?4);
?static?HuoChe?h2?=?new?HuoChe("依維柯",?1000,?20);
?static?PiKa?p1?=?new?PiKa("皮卡雪6",?450,?4?,2);
?
?static?Che[]?ches?=?{null,?k1,?k2,?k3,?h1,?h2,?p1};
?
?private?static?int?totalPrice?=?0;
?private?static?int?totalPCapacity?=?0;
?private?static?int?totalGCapacity?=?0;
?
?public?static?void?main(String[]?args)?{
??Test?test?=?new?Test();
??boolean?boo?=?true;
??
??System.out.println("歡迎使用嗒嗒租車系統");
??
??for(?;?boo;?)?{
???
???System.out.println("1.進入系統\n2.退出系統");
???Scanner?system?=?new?Scanner(System.in);
???int?str?=?system.nextInt();
???
???if(str?==?1)?{
????System.out.println("您可租用的車輛信息如下");
????System.out.println("序號\t車名\t租金(元/天)\t載人(人)\t載貨(噸)");
????test.printCarInfo();
????
????System.out.println("請輸入您想租用車輛的數目");
????int?rentNum?=?new?Scanner(System.in).nextInt();
????Che[]?totalChe?=?new?Che[rentNum?+?1];
????totalChe[0]?=?null;
????
????for(int?num?=?0;?num?<?rentNum;?num++)?{
?????System.out.println("請輸入第?"?+?(num?+?1)?+?"?輛車的序號\t");
?????int?carNo?=?new?Scanner(System.in).nextInt();
?????
?????totalChe[(num?+?1)]?=?ches[carNo];
?????totalPrice?=?totalPrice?+?ches[carNo].getCarPrice();
?????totalPCapacity?=?totalPCapacity?+?ches[carNo].getCarPCapacity();
?????totalGCapacity?=?totalGCapacity?+?ches[carNo].getCarGCapacity();
????}
????
????System.out.println("請輸入租用天數");
????int?rentDay?=?new?Scanner(System.in).nextInt();
????
????System.out.println("您租用的車輛信息如下");
????System.out.println("序號\t車名\t租金(元/天)\t載人(人)\t載貨(噸)");
????for(int?i?=?1;?i?<?rentNum?+?1;?i++)?{
?????System.out.print(i?+?"\t");
?????System.out.print(totalChe[i].getCarName()?+?"\t");
?????System.out.print(totalChe[i].getCarPrice()?+?"\t\t");
?????System.out.print(totalChe[i].getCarPCapacity()?+?"\t");
?????System.out.print(totalChe[i].getCarGCapacity()?+?"\t");
?????System.out.println();
????}
????
????System.out.println("總租金為?"?+?totalPrice?*?rentDay?+?"?元");
????System.out.println("可載人數為?"?+?totalPCapacity?+?"?人");
????System.out.println("可載貨物為?"?+?totalGCapacity?+?"?噸");
????
????boo?=?false;
???}?else?if(str?==?2){
????System.out.println("很遺憾,期待您的下次使用");
????boo?=?false;
???}?else?{
????System.out.println("您的輸入有誤,請重新輸入");
???}
??}
?}
?
?public?void?printCarInfo()?{
??
??for(int?i?=?1;?i?<?ches.length;?i++)?{
???System.out.print(i?+?"\t");
???System.out.print(ches[i].getCarName()?+?"\t");
???System.out.print(ches[i].getCarPrice()?+?"\t\t");
???System.out.print(ches[i].getCarPCapacity()?+?"\t");
???System.out.print(ches[i].getCarGCapacity()?+?"\t");
???System.out.println();
??}
?}
}

正在回答

4 回答

test.printCarInfo(); 這是什么意思 哪里來的這方法

0 回復 有任何疑惑可以回復我~
很好很強大

0 回復 有任何疑惑可以回復我~

我想問一下,static?Che[]?ches?=?{null,?k1,?k2,?k3,?h1,?h2,?p1};數組前面的null是什么?求大神指導

0 回復 有任何疑惑可以回復我~
#1

victor_Lau

代表 0啊
2016-07-27 回復 有任何疑惑可以回復我~

漂亮。。漂亮。。。漂亮 ? ?用接口 也行吧

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
Java入門第二季 升級版
  • 參與學習       531142    人
  • 解答問題       6326    個

課程升級!以終為始告別枯燥,在開發和重構中體會Java面向對象編程的奧妙

進入課程

交作業:嗒嗒租車系統

我要回答 關注問題
微信客服

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

幫助反饋 APP下載

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

公眾號

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