package?com.exc;import?java.util.Scanner;public?class?DDRental?{ public?static?void?main(String[]?args)?{ int?money?=0; Car[]?carForRentCars?=?{new?AutoCar("奧迪",?500,?4),?new?AutoCar("馬自達(dá)",?400,?4),? new?AutoCar("金龍",?800,?20)?,new?Trunk("松花江",?400,?4),? new?Trunk("依維柯",?1000,?20),?new?PickCar("皮卡",?450,?2,?4)}; System.out.println("歡迎使用噠噠租車系統(tǒng)~~~"); System.out.println("您是否要租車:1是???2否"); Scanner?sc?=?new?Scanner(System.in); boolean?flag?=?true; while?(flag)?{ int?rent?=?sc.nextInt(); switch?(rent)?{ case?1: System.out.println("您可租車的類型及其價(jià)格表如下:"); System.out.println("序號(hào)\t汽車名稱\t租金\t\t容量"); for?(int?i?=?0;?i?<?carForRentCars.length;?i++)?{ if?(carForRentCars[i]?instanceof?AutoCar)?{ AutoCar?aCar?=?(AutoCar)?carForRentCars[i]; System.out.println((i+1)?+?"\t"?+?aCar.name?+"\t"?+?aCar.rent?+?"元/天\t\t載人:"?+?aCar.getPeopleCapacity()?+"人"); }?else?if?(carForRentCars[i]?instanceof?Trunk)?{ Trunk?trunk?=?(Trunk)?carForRentCars[i]; System.out.println((i+1)?+?"\t"?+?trunk.name?+"\t"?+?trunk.rent?+?"元/天\t\t載人:"?+?trunk.getCargoCapacity()?+"人"); }?else?if?(carForRentCars[i]?instanceof?PickCar)?{ PickCar?pCar?=?(PickCar)?carForRentCars[i]; System.out.println((i+1)?+?"\t"?+?pCar.name?+"\t"?+?pCar.rent?+?"元/天\t\t載人:"?+??pCar.getPeopleCapacity()?+? "人???載貨:"+?pCar.getCargoCapacity()?+"噸"); } } flag?=?false; break; case?2: System.out.println("感謝您的光臨,期待下次與您再見(jiàn),祝您生活愉快!"); flag?=?false; break; default: System.out.println("您好,您的輸入不正確。請(qǐng)根據(jù)提示正確輸入!"); break; } } System.out.println("請(qǐng)輸入您要租車的數(shù)量:"); int?count?=?sc.nextInt(); for?(int?i?=?1;?i?<=?count;?i++)?{ System.out.println("請(qǐng)輸入第"?+?i?+"輛車的序號(hào):"); int?id?=?sc.nextInt(); switch?(id)?{ case?1: money?+=?carForRentCars[0].getRent(); break; case?2: money?+=?carForRentCars[1].getRent(); break; case?3: money?+=?carForRentCars[2].getRent(); break; case?4: money?+=?carForRentCars[3].getRent(); break; case?5: money?+=?carForRentCars[4].getRent(); break; case?6: money?+=?carForRentCars[5].getRent(); break; default: break; } } System.out.println("請(qǐng)輸入租車天數(shù):"); int?day?=?sc.nextInt(); System.out.println("您的帳單:"?+?day*money?+?"元?。?!"); }}class?Car{ String?name; int?rent; public?Car()?{} public?String?getName()?{ return?name; } public?void?setName(String?name)?{ this.name?=?name; } public?double?getRent()?{ return?rent; } public?void?setRent(int?rent)?{ this.rent?=?rent; } }class?AutoCar?extends?Car{ private?int?peopleCapacity; public?AutoCar()?{} public?AutoCar(String?name,?int?rent,?int?peopleCapacity)?{ this.name?=?name; this.rent?=?rent; this.peopleCapacity?=?peopleCapacity; } public?int?getPeopleCapacity()?{ return?peopleCapacity; } public?void?setPeopleCapacity(int?peopleCapacity)?{ this.peopleCapacity?=?peopleCapacity; } }class?Trunk?extends?Car{ private?int?cargoCapacity; public?Trunk()?{} public?Trunk(String?name,?int?rent,?int?cargoCapacity)?{ this.name?=?name; this.rent?=?rent; this.cargoCapacity?=?cargoCapacity; } public?int?getCargoCapacity()?{ return?cargoCapacity; } public?void?setCargoCapacity(int?cargoCapacity)?{ this.cargoCapacity?=?cargoCapacity; } }class?PickCar?extends?Car{ private?int?cargoCapacity; private?int?peopleCapacity; public?PickCar()?{} public?PickCar(String?name,?int?rent,?int?cargoCapacity,?int?peopleCapacity)?{ this.name?=?name; this.rent?=?rent; this.cargoCapacity?=?cargoCapacity; this.peopleCapacity?=?peopleCapacity; } public?int?getCargoCapacity()?{ return?cargoCapacity; } public?void?setCargoCapacity(int?cargoCapacity)?{ this.cargoCapacity?=?cargoCapacity; } public?int?getPeopleCapacity()?{ return?peopleCapacity; } public?void?setPeopleCapacity(int?peopleCapacity)?{ this.peopleCapacity?=?peopleCapacity; } }
2019-10-26
看到我想給你一耳巴子 哈哈
2019-07-25
對(duì)不起各位,格式亂了,這個(gè)問(wèn)題就當(dāng)我沒(méi)發(fā)布過(guò)