一、技术要点
二、运行效果
三、代码实现
1、Car类
package CarRentSystem.entity;
public class Car {
private String id;
private String type;
private int dayMoney;
public Car() {
}
public Car(String id, String type, int dayMoney) {
this.id = id;
this.type = type;
this.dayMoney = dayMoney;
}
public double getMoney(int days) {
double money = this.getDayMoney() * days;
return money;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public int getDayMoney() {
return dayMoney;
}
public void setDayMoney(int dayMoney) {
this.dayMoney = dayMoney;
}
@Override
public String toString() {
return "Car{" +
"id='" + id + ''' +
", type='" + type + ''' +
", dayMoney=" + dayMoney +
'}';
}
}
2、Bus类
package CarRentSystem.entity;
public class Bus extends Car {
private int seatCount;
public Bus() {
}
public Bus(String id, String type, int dayMoney, int seatCount) {
super(id, type, dayMoney);
this.seatCount = seatCount;
}
@Override
public double getMoney(int days) {
double money = this.getDayMoney() * days;
if (days >= 150) {
money *= 0.6;
} else if (days >= 30) {
money *= 0.7;
} else if (days >= 7) {
money *= 0.8;
} else if (days >= 3) {
money *= 0.9;
}
return money;
}
public int getSeatCount() {
return seatCount;
}
public void setSeatCount(int seatCount) {
this.seatCount = seatCount;
}
@Override
public String toString() {
return "Bus{" + super.toString() +
"seatCount=" + seatCount +
'}';
}
}
3、Saloon类
package CarRentSystem.entity;
public class Saloon extends Car {
private String typeNum;
public Saloon() {
}
public Saloon(String id, String type, int dayMoney, String typeNum) {
super(id, type, dayMoney);
this.typeNum = typeNum;
}
@Override
public double getMoney(int days) {
double money = this.getDayMoney() * days;
if (days >= 150) {
money *= 0.66;
} else if (days >= 30) {
money *= 0.77;
} else if (days >= 7) {
money *= 0.88;
}
return money;
}
public String getTypeNum() {
return typeNum;
}
public void setTypeNum(String typeNum) {
this.typeNum = typeNum;
}
@Override
public String toString() {
return "Saloon{" + super.toString() +
"typeNum='" + typeNum + ''' +
'}';
}
}
4、主程序类
package CarRentSystem.test;
import CarRentSystem.entity.Bus;
import CarRentSystem.entity.Saloon;
import java.util.Scanner;
public class CarSystem {
public static void main(String[] args) {
System.out.println("👏👏👏👏👏欢迎使用秋名山汽车租赁系统👏👏👏👏👏");
System.out.println("1、舒适轿车🚗 2、多座客车🚐");
Scanner scanner = new Scanner(System.in);
System.out.print("请选择您要租赁的汽车类型:");
int typeNum = scanner.nextInt();
if (typeNum == 1) {
Saloon saloon = new Saloon();
System.out.print("请选择您要租赁的汽车品牌:(1.别克 2.宝马)");
int pingNum2 = scanner.nextInt();
if (pingNum2 == 1) {
System.out.print("请选择您要租赁的汽车类型:(1.林荫大道 2.GL8)");
} else if (pingNum2 == 2) {
System.out.print("请选择您要租赁的汽车类型:(1.X8 2.550i)");
}
int seatNum2 = scanner.nextInt();
System.out.print("请选择您要租赁的天数:");
int dayNum2 = scanner.nextInt();
if (pingNum2 == 1 && seatNum2 == 1) {
saloon.setDayMoney(300);
saloon.setId("京A12345");
saloon.setType("别克");
saloon.setTypeNum("林荫大道");
System.out.println("分配给您的汽车牌号是:" + saloon.getId());
} else if (pingNum2 == 1 && seatNum2 == 2) {
saloon.setDayMoney(300);
saloon.setId("京A67890");
saloon.setType("别克");
saloon.setTypeNum("GL8");
System.out.println("分配给您的汽车牌号是:" + saloon.getId());
} else if (pingNum2 == 2 && seatNum2 == 1) {
saloon.setDayMoney(300);
saloon.setId("京B98765");
saloon.setType("宝马");
saloon.setTypeNum("X8");
System.out.println("分配给您的汽车牌号是:" + saloon.getId());
} else if (pingNum2 == 2 && seatNum2 == 2) {
saloon.setDayMoney(300);
saloon.setId("京B43210");
saloon.setType("宝马");
saloon.setTypeNum("550i");
System.out.println("分配给您的汽车牌号是:" + saloon.getId());
}
System.out.println("您需要支付的租赁费用是:" + saloon.getMoney(dayNum2) + "元");
System.out.println("您租赁的汽车信息为:" + saloon.toString());
} else if (typeNum == 2) {
Bus bus = new Bus();
System.out.print("请选择您要租赁的汽车品牌:(1.五菱宏光 2.金杯)");
int pingNum1 = scanner.nextInt();
System.out.print("请选择您要租赁的座位数:(1.8座 2.12座)");
int seatNum1 = scanner.nextInt();
System.out.print("请选择您要租赁的天数:");
int dayNum1 = scanner.nextInt();
if (pingNum1 == 1 && seatNum1 == 1) {
bus.setDayMoney(800);
bus.setId("京A66666");
bus.setType("五菱宏光");
bus.setSeatCount(8);
System.out.println("分配给您的汽车牌号是:" + bus.getId());
} else if (pingNum1 == 1 && seatNum1 == 2) {
bus.setDayMoney(1500);
bus.setId("京A88888");
bus.setType("五菱宏光");
bus.setSeatCount(12);
System.out.println("分配给您的汽车牌号是:" + bus.getId());
} else if (pingNum1 == 2 && seatNum1 == 1) {
bus.setDayMoney(800);
bus.setId("京A66666");
bus.setType("金杯");
bus.setSeatCount(8);
System.out.println("分配给您的汽车牌号是:" + bus.getId());
} else if (pingNum1 == 2 && seatNum1 == 2) {
bus.setDayMoney(1500);
bus.setId("京A66666");
bus.setType("金杯");
bus.setSeatCount(12);
System.out.println("分配给您的汽车牌号是:" + bus.getId());
}
System.out.println("您需要支付的租赁费用是:" + bus.getMoney(dayNum1) + "元");
System.out.println("您租赁的汽车信息为:" + bus.toString());
}
}
}