慕粉0001535814
2017-08-07 17:55:26
package?rentCar.system;
import?java.util.Scanner;
public?class?App?{
?public?static?void?main(String[]?args)?{
??App?enterSystem?=?new?App();
??enterSystem.rentCarSystem();
?}
?
?Car[]?cI?=?{new?Truck(1,?"大貨車(chē)",?2,?5,?300)?//各車(chē)輛信息錄入
?????,?new?Bus(2,?"巴士",?50,?0,?200)
?????,?new?Pickup(3,?"皮卡",?2,?3,?100)
?????,?new?Jaguar(4,?"捷豹",?4,?0,?150)};
?//詢問(wèn)是否需要租車(chē)
?void?rentCarSystem()?{
??System.out.println("歡迎使用嗒嗒租車(chē)系統(tǒng)!");
??System.out.println("請(qǐng)問(wèn)您是否租車(chē):1.是\t2.否");
??Scanner?input?=?new?Scanner(System.in);
??int?answer?=?input.nextInt();
??if?(answer?==?1)?{
???carInformation();
??}?else?if(answer?==?2)?{
???System.out.println("謝謝使用!");
??}?else?{
???System.out.println("輸入有誤!程序自爆!");
???System.exit(0);
??}
?}
?//車(chē)輛信息
?void?carInformation(){
??System.out.println("正在為您載入租車(chē)系統(tǒng)...\n");
??System.out.println("=============\t\t車(chē)輛租用列表\t\t=============");
??System.out.println("序號(hào)\t車(chē)名\t載客量(人)\t載貨量(噸)\t租金(元/天)");
??for?(int?i?=?0;?i?<?cI.length;?i++)?{
???System.out.println();
???System.out.println(cI[i].toString());
??}
??System.out.println("=============\t\t歡迎使用本系統(tǒng)\t\t=============\n");
??carRentNumber();
?}
?//詢問(wèn)租車(chē)數(shù)量
?void?carRentNumber()?{
??System.out.println("請(qǐng)問(wèn)需要租幾輛車(chē)?");
??Scanner?input?=?new?Scanner(System.in);
??int?answer?=?input.nextInt();?//得到租車(chē)數(shù)量值
??carRentType(answer);?//租車(chē)類型
?}
?//詢問(wèn)租車(chē)類型
?void?carRentType(int?num)?{
??String[]?name?=?new?String[num];??//租用車(chē)輛名字
??double?totalRent?=?0;?//總租金
??double?totalBurden?=?0;?//總載貨量
??int?totalBusload?=?0;?//總載客量
??System.out.println("====================================================");
??System.out.println("溫馨提示:車(chē)輛序列號(hào)范圍(1-"?+?cI.length?+?")");
??System.out.println("====================================================");
??System.out.println();
??for?(int?i?=?1;?i?<=?num;?i++)?{
???System.out.print("請(qǐng)輸入租用第"?+?i?+?"輛車(chē)的序號(hào):");
???Scanner?input?=?new?Scanner(System.in);
???int?id?=?input.nextInt();?//得到車(chē)輛ID序號(hào)
???if?(id?<=?cI.length?&&?id?>=?1)?{
????totalRent?+=?cI[id-1].rent;??//得到全部租用車(chē)輛的總租金
????totalBurden?+=?cI[id-1].burden;?//得到總載貨量
????totalBusload?+=?cI[id-1].busload;?//得到總載客量
????name[i-1]?=?cI[id-1].name;???//為數(shù)組name賦值?租用的車(chē)輛名
???}?else?{
????System.out.println("輸入有誤!程序啟動(dòng)自爆!");
????System.exit(0);
???}
??}
??double?finalRent?=?carRentDay(totalRent);
??rentCarBill(name,?totalBusload,?totalBurden,?finalRent);
?}
?//詢問(wèn)租車(chē)天數(shù)并返回租車(chē)總費(fèi)用
?double?carRentDay(double?total)?{
??System.out.println("請(qǐng)輸入您要租用的天數(shù):?");
??Scanner?input?=?new?Scanner(System.in);
??int?day?=?input.nextInt();
??return?total?*=?day;?
?}
?//顯示租用車(chē)輛名、?租用車(chē)輛總載客數(shù)、總載貨量、總租金
?void?rentCarBill(String[]?name,?int?busload,?double?burden,?double?rent)?{
??System.out.println("正在為您生成租車(chē)清單...\n");
??System.out.println("=============??本次租車(chē)清單??=============");
??System.out.println("您租用以下車(chē):\n");
??for?(int?i?=0;?i?<?name.length;?i++)?{
???System.out.print(name[i]?+?"\t\t");
???if?((i?+?1)?%?8?==?0)
????System.out.println("\n");
??}
??System.out.println("\n\n總載客量:?"?+?busload?+?"?人\t\t"?+?"總載貨量:?"?+?burden?+?"?噸\t"?+?"總費(fèi)用:?"?+?rent?+?"?元\n");
??System.out.println("=============??歡迎再次使用??=============");
??System.exit(0);
?}
}
2 回答

wj903829182
TA貢獻(xiàn)5條經(jīng)驗(yàn) 獲得超3個(gè)贊
這是C語(yǔ)言思維,沒(méi)有面向?qū)ο蟮乃季S,這是java初學(xué)者的寫(xiě)著好玩的代碼,基本使用java以后都不會(huì)寫(xiě)這樣的代碼,java用了些anroid,web項(xiàng)目,不會(huì)出現(xiàn)這樣的形式代碼

William_Jing
TA貢獻(xiàn)2條經(jīng)驗(yàn) 獲得超1個(gè)贊
你的這個(gè)程序是用面向過(guò)程的思維方式解決的,有沒(méi)有想過(guò)用面向?qū)ο蠼鉀Q一下試試?
添加回答
舉報(bào)
0/150
提交
取消