package?com.company.Pojo;
public?class?Car?{//汽車類父類
????protected?int?id;//汽車編號
????protected?String?brand;//品牌
????protected?double?price;//租用價格
????public?int?getId()?{
????????return?id;
????}
????public?void?setId(int?id)?{
????????this.id?=?id;
????}
????public?String?getBrand()?{
????????return?brand;
????}
????public?void?setBrand(String?brand)?{
????????this.brand?=?brand;
????}
????public?double?getPrice()?{
????????return?price;
????}
????public?void?setPrice(double?price)?{
????????this.price?=?price;
????}
????public?void?show(){
????System.out.println("汽車是交通工具有運輸的功能");
}
}
package?com.company.Pojo;
//???
public?class?PassengerCar?extends?Car?{
????protected?int?pc;//載客量
????public?int?getPc()?{
????????return?pc;
????}
????public?void?setPc(int?pc)?{
????????this.pc?=?pc;
????}
????public?PassengerCar(int?id,String?brand,?double?price,?int?pc)?{
????????this.id=id;
????????this.brand=?brand;
????????this.price=price;
????????this.pc=pc;
????}
????public?void?show(){
????????System.out.println(id+"\t"+brand+"\t"+price+"元/天"+"\t載客:"+pc+"人");
????}
}
package?com.company.Pojo;
public?class?PickUpCar?extends?Car{
????private?int?pc;//?????
????private?int?lc;//?????
????public?int?getPc()?{
????????return?pc;
????}
????public?void?setPc(int?pc)?{
????????this.pc?=?pc;
????}
????public?int?getLc()?{
????????return?lc;
????}
????public?void?setLc(int?lc)?{
????????this.lc?=?lc;
????}
????//?вι?????
????public?PickUpCar(int?id,String?brand,?double?price,?int?pc,int?lc){
????????this.id=id;
????????this.brand=brand;
????????this.price=price;
????????this.pc=pc;
????????this.lc=lc;
????}
????public?void?show(){
????????System.out.println(id+"\t"+brand+"\t"+price+"元/天"+"\t載客:"+pc+"人"+"\t載貨:"+lc+"噸");
????}
}
package?com.company.Pojo;
import?java.util.Scanner;
public?class?Run?{
????double?count=0.0;//租用單個品牌的費用
????double?sum?=?0.0;//計算租車總金額
????int?day?=?0;//租用天數
????int?num?=?0;//租用數量
????Car[]?car?=?{
????????????new?PassengerCar(1,?"???蘭博基尼雷文頓",?5000,?5),
????????????new?PassengerCar(2,?"?雙層多麗蘭大巴車",?1000,?50),
????????????new?TruckCar(3,?"???多利卡中型貨車",?500,?15),
????????????new?TruckCar(4,?"?東風雪鐵龍大貨車",?1000,?50),
????????????new?PickUpCar(5,?"??皮卡雪皮卡車",?200,?4,?5)
????};
????public?void?run()?{
????????System.out.println("歡迎使用噠噠租車系統");
????????System.out.println("請問您是否要租用車輛:?1是?0否");
????????Scanner?input?=?new?Scanner(System.in);
????????int?select?=?input.nextInt();//是否要租車
????????if?(!(select?==?0?||?select?==?1))?{
????????????System.out.println("輸入錯誤系統自動退出");
????????????System.exit(0);
????????}?else?if?(select?==?0)?{
????????????System.out.println("那么你是來搞笑的嗎?");
????????????System.exit(0);
????????}?else?{
????????????System.out.println("感謝您使用我們的租車系統請問您需要租什么樣的車呢這是我們的汽車類型以及價位表:");
????????}
????????System.out.println("序號\t汽車品牌\t\t\t租金\t容量");
????????for?(Car?car1?:?car)?{
????????????car1.show();
????????}
????????System.out.println("請輸入您要租車的序號");
????????int?select1?=?input.nextInt();//輸入車輛id
????????if?(!(select1?>?0?&&?select1?<=?5))?{
????????????System.out.println("您輸入的序號有誤系統自動退出");
????????????System.exit(0);
????????}?else?{
????????????System.out.println("您要租的車輛為:");
????????????for?(int?i?=?0;?i?<?car.length;?i++)?{
????????????????if?(i?==?select1?-?1)?{
????????????????????car[i].show();
????????????????}
????????????}
????????????System.out.println("請問您需要租用的汽車數量?");
????????????int?select2?=?input.nextInt();//汽車數量
????????????if?(!(select2?>?0?&&?select2?<?50))?{
????????????????System.out.println("您輸入的輛數有誤系統自動退出");
????????????????System.exit(0);
????????????}?else?{
????????????????num?=?select2;
????????????}
????????????System.out.println("請問您需要租用多長時間呢?");
????????????int?select3?=?input.nextInt();//租車時間
????????????if?(!(select3?>?0?||?select3?<?50))?{
????????????????System.out.println("您輸入的天數有誤系統自動退出");
????????????}?else?{
????????????????day?=?select3;
????????????}
????????????count?=?car[select1?-?1].price?*?day?*?num;
????????????sum+=count;
????????????System.out.println("您的目前的租車金額為:"+sum);
????????????System.out.println("如果您還需要繼續租用其他車輛請繼續輸入對應的序號,如果您已經完成租車請輸入8為您結算租車金額");
????????????int?select4?=?input.nextInt();
????????????if?(select4?==?8)?{
????????????????System.out.println("您租的車的品牌為:"?+?car[select1?-?1].brand
????????????????????????+?"租車天數為:"?+?day?+?"天"?+?"租車數量為:"?+?num?+?"輛"?+?"租車費用為:"?+?count?+?"元");
????????????????System.exit(0);
????????????}?else?if?(!(select4?>?0?||?select4?<=?5))?{
????????????????System.out.println("您的輸入不合法系統自動退出");
????????????????System.exit(0);
????????????}?else?{
????????????????System.out.println("您還要租的車輛為:");
????????????????for?(int?j?=?0;?j?<?car.length;?j++)?{
????????????????????if?(select4?-?1?==?j)?{
????????????????????????car[j].show();
????????????????????}
????????????????}
????????????}
????????????System.out.println("請問您需要租用的汽車數量?");
????????????int?select5?=?input.nextInt();
????????????if?(!(select5?>?0?&&?select5?<?50))?{
????????????????System.out.println("您輸入的輛數有誤系統自動退出");
????????????????System.exit(0);
????????????}?else?{
????????????????num?=?select5;
????????????}
????????????System.out.println("請問您需要租用多長時間呢?");
????????????int?select6?=?input.nextInt();
????????????if?(!(select6?>?0?||?select6?<50))?{
????????????????System.out.println("您輸入的天數有誤系統自動退出");
????????????}?else?{
????????????????day?=?select6;
????????????}
?????????????count=?car[select4?-?1].price?*?day?*?num;
????????????sum=count+sum;
????????????System.out.println("如果您已經完成租車請輸入8為您結算租車金額");
????????????int?select7?=?input.nextInt();
????????????if?(select7?==?8)?{
????????????????System.out.println("您租的車的品牌為:"?+?car[select4?-?1].brand?+?"租車天數為:"?+?day?+?"天"?+?"租車數量為:"?+?num?+?"輛"?+?"總共需要支付金額為:"?+?count?+?"元");
????????????????System.out.println("您總共需要支付的租車費用為"+sum+"感謝您的惠顧謝謝光臨");
????????????}
????????}
????}
}
package?com.company.Pojo;
//貨車
public?class?TruckCar?extends?Car?{
????private?int?lc;//載貨量
????public?int?getLc()?{
????????return?lc;
????}
????public?void?setLc(int?lc)?{
????????this.lc?=?lc;
????}
????//有參構造函數
????public?TruckCar(int?id,?String?brand,?double?price,?int?lc)?{
????????this.id?=?id;
????????this.brand?=?brand;
????????this.price?=?price;
????????this.lc?=?lc;
????}
????????//汽車可以運輸貨物
????????public?void?show(){
????????????System.out.println(id?+?"\t"?+?brand?+?"\t"?+?price?+?"元/天"?+?"\t載貨:"?+?lc?+?"噸");
????????}
}
package?com.company;
import?com.company.Pojo.Car;
import?com.company.Pojo.PassengerCar;
import?com.company.Pojo.Run;
import?java.util.Scanner;
public?class?Test?{
????public?static?void?main(String[]?args)?{
????????Run?r=new?Run();
????????r.run();
????}
}
2019-10-10
這個程序后面重了,感覺
2019-10-10
很強,好多教的都用到了
2019-09-24
能解答一下這句語句嗎?不是很懂這個for是怎么用的?
2019-09-07
運行結果如下圖