日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

java实现dvd租赁系统_Java编写汽车租赁系统

發(fā)布時間:2024/9/15 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java实现dvd租赁系统_Java编写汽车租赁系统 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

來源:blog.csdn.net/weixin_44889894


題目要求:

1、汽車租賃信息表如下:2、類和屬性:3、運(yùn)行效果:

效果實現(xiàn):

代碼實現(xiàn):

1、車類:

package homework.exam;public abstract class Vehicle { private String num; private String brand; private double rent; public String getNum() { return num; } public void setNum(String num) { this.num = num; } public String getBrand() { return brand; } public void setBrand(String brand) { this.brand = brand; } public double getRent() { return rent; } public void setRent(double rent) { this.rent = rent; } public Vehicle() { } //含參構(gòu)造 public Vehicle(String num, String brand, double rent) { this.num = num; this.brand = brand; this.rent = rent; } @Override public String toString() { return "汽車{" + "車牌號='" + num + '\'' + ", 品牌='" + brand + '\'' + ", 日租金=" + rent + '}'; } public abstract double totalmoney(int days , double rent); public abstract boolean equals(Vehicle o);}

2、汽車類:

package homework.exam;public class Cars extends Vehicle{ private String type; public String getType() { return type; } public void setType(String type) { this.type = type; } public Cars(String brand,String type) { this.type = type; } public Cars(String num, String brand, double rent, String type) { super(num, brand, rent); this.type = type; } @Override public String toString() { return "Cars{" + "type='" + type + '\'' + '}'; } //計算小汽車的總租金 @Override public double totalmoney(int days, double rent) { if (days>7){ return days*rent*0.9; }else if (days>30){ return days*rent*0.8; }else if (days>150){ return days*rent*0.7; } return days*rent; } //重寫equals方法 @Override public boolean equals(Vehicle o) { if (o instanceof Cars){ Cars cars= (Cars) o; return this.getType().equals(cars.getType())&&this.getBrand().equals(o.getBrand()); } return false; }}

3、客車類:

package homework.exam;public class Bus extends Vehicle { private String seat; public String getSeat() { return seat; } public void setSeat(String seat) { this.seat = seat; } public Bus(String num, String brand, double rent, String seat) { super(num, brand, rent); this.seat = seat; } //計算客車的租金 @Override public double totalmoney(int days, double rent) { if (days>=3){ return days*rent*0.9; }else if (days>=7){ return days*rent*0.8; }else if (days>=30){ return days*rent*0.7; }else if (days>=150){ return days*rent*0.6; } return days*rent; } //重寫equals方法 @Override public boolean equals(Vehicle o) { return false; }}

4、車輛管理類:

package homework.exam;public class CarRent { //創(chuàng)建汽車數(shù)組,將汽車的信息放在數(shù)組中 public Cars[] carMake(){ Cars c1 = new Cars("京NY28588", "寶馬", 800, "x6"); Cars c2 = new Cars("京CNY3284", "寶馬", 600, "550i"); Cars c3 = new Cars("京NT37465", "別克", 300, "林蔭大道"); Cars c4 = new Cars("京NT96928", "別克", 600, "GL8"); Cars[] arr1 ={c1,c2,c3,c4}; return arr1; } //創(chuàng)建客車數(shù)組,將汽車的信息放在數(shù)組中 public Bus[] busMake(){ Bus b1 = new Bus("京6566754", "金杯", 800, "16座"); Bus b2 = new Bus("京8696667", "金龍", 800, "16座"); Bus b3 = new Bus("京9696996", "金杯", 1500, "34座"); Bus b4 = new Bus("京8696998", "金龍", 1500, "34座"); Bus[] arr2={b1,b2,b3,b4}; return arr2; }}

5、業(yè)務(wù)服務(wù)類:

package homework.exam;import java.util.Scanner;public class CarService { public void rentcar(){ System.out.println("**********歡迎光臨秋名山守望者汽車租賃公司**********"); Scanner sc = new Scanner(System.in); System.out.println("1,轎車 2,客車"); System.out.print("請輸入您要租賃的汽車類型:"); int i = sc.nextInt(); CarRent carRent = new CarRent(); //創(chuàng)建車庫對象 Cars[] cars = carRent.carMake(); //拿到轎車數(shù)組對象 Cars car=null; Bus[] buses = carRent.busMake(); //拿到客車數(shù)組對象 Bus bus=null; //判斷用戶選擇的車型 if (i==1){ System.out.print("請選擇你要租賃的汽車品牌:(1,別克 2,寶馬)"); int i1 = sc.nextInt(); if (i1==1){ System.out.print("請輸入你要租賃的汽車類型:(1,林蔭大道 2,GL8 )"); }else { System.out.print("請輸入你要租賃的汽車類型:(1,x6 2,550i )"); } String i2 = sc.next(); //遍歷汽車數(shù)組,拿到用戶選擇的汽車 for (int j = 0; j < cars.length; j++) { if (cars[j].getType().equals(i2)){ //當(dāng)選擇的車的類型與數(shù)組中的匹配時 car=cars[j]; //將車賦值給car break; } } System.out.print("請輸入你要租賃的天數(shù):"); int days = sc.nextInt(); System.out.print("分配給你的汽車牌號是:"); System.out.println(car.getNum()); //獲取汽車的車牌 double totalmoney =0; //調(diào)用total totalmoney = car.totalmoney(days, car.getRent()); //計算用戶的租金 System.out.print("你需要支付的租賃分費(fèi)用是:"); System.out.print(totalmoney); }else if (i==2){ System.out.print("請選擇你要租賃的汽車品牌:(1,金龍 2,金杯)"); String i2 = sc.next(); System.out.print("請輸入你要租賃的汽車座位數(shù):(1,16座 2,34座)"); String i3 = sc.next(); //遍歷客車數(shù)組,拿到用戶選擇的客車 for (int j = 0; j < buses.length; j++) { //當(dāng)輸入的客車的車牌和座位與數(shù)組中的相等,就選出用戶選擇的車 if (buses[j].getBrand().equals(i2)&&buses[j].getSeat().equals(i3)){ bus=buses[j]; //將選擇的車輛賦值給bus break; } } System.out.print("請輸入你要租賃的天數(shù):"); int days = sc.nextInt(); System.out.print("分配給你的汽車牌號是:"); System.out.println(); System.out.println(bus.getNum()); //拿到用戶選擇的車牌號 double totalmoney = 0; //調(diào)用totalmoney方法 totalmoney=bus.totalmoney(days, bus.getRent()); //用用戶輸入的天數(shù)。來計算租金 System.out.print("你需要支付的租賃分費(fèi)用是:"); System.out.print(totalmoney); } }}

6、測試類:

package homework.exam;public class Test { public static void main(String[] args) { CarService cs = new CarService(); cs.rentcar(); }}

控制臺輸入的內(nèi)容,我選擇的是輸入字符串類型,沒有按照效果圖上,如果你做的話,你可以用三元運(yùn)算符來實現(xiàn)哦!

PS:如果覺得我的分享不錯,歡迎大家隨手點(diǎn)贊、在看。END

總結(jié)

以上是生活随笔為你收集整理的java实现dvd租赁系统_Java编写汽车租赁系统的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。