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("馬自達(dá)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("歡迎使用嗒嗒租車系統(tǒng)");
??
??for(?;?boo;?)?{
???
???System.out.println("1.進(jìn)入系統(tǒng)\n2.退出系統(tǒng)");
???Scanner?system?=?new?Scanner(System.in);
???int?str?=?system.nextInt();
???
???if(str?==?1)?{
????System.out.println("您可租用的車輛信息如下");
????System.out.println("序號(hào)\t車名\t租金(元/天)\t載人(人)\t載貨(噸)");
????test.printCarInfo();
????
????System.out.println("請(qǐng)輸入您想租用車輛的數(shù)目");
????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("請(qǐng)輸入第?"?+?(num?+?1)?+?"?輛車的序號(hào)\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("請(qǐng)輸入租用天數(shù)");
????int?rentDay?=?new?Scanner(System.in).nextInt();
????
????System.out.println("您租用的車輛信息如下");
????System.out.println("序號(hào)\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("可載人數(shù)為?"?+?totalPCapacity?+?"?人");
????System.out.println("可載貨物為?"?+?totalGCapacity?+?"?噸");
????
????boo?=?false;
???}?else?if(str?==?2){
????System.out.println("很遺憾,期待您的下次使用");
????boo?=?false;
???}?else?{
????System.out.println("您的輸入有誤,請(qǐng)重新輸入");
???}
??}
?}
?
?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();
??}
?}
}
2017-10-18
test.printCarInfo(); 這是什么意思 哪里來(lái)的這方法
2016-03-18
2015-12-09
我想問(wèn)一下,static?Che[]?ches?=?{null,?k1,?k2,?k3,?h1,?h2,?p1};數(shù)組前面的null是什么?求大神指導(dǎo)
2015-10-05
漂亮。。漂亮。。。漂亮 ? ?用接口 也行吧