You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.5 KiB
35 lines
1.5 KiB
public class TestCar {
|
|
public static void main(String[] args) {
|
|
// 创建3个Car对象(使用不同构造方法)
|
|
Car car1 = new Car("京A12345", "丰田", "凯美瑞", 280.0);
|
|
Car car2 = new Car("沪B67890", "本田", "雅阁"); // 日租金默认300元
|
|
Car car3 = new Car("粤C11111", "大众", "帕萨特", 320.0);
|
|
|
|
// 打印所有车辆信息
|
|
System.out.println("=== 初始车辆信息 ===");
|
|
car1.displayInfo();
|
|
car2.displayInfo();
|
|
car3.displayInfo();
|
|
|
|
// 测试租车/还车业务
|
|
System.out.println("\n=== 测试租车/还车 ===");
|
|
car1.rentCar(); // 第一次租车
|
|
car1.rentCar(); // 重复租车(提示已出租)
|
|
car1.returnCar(); // 第一次还车
|
|
car1.returnCar(); // 重复还车(提示未出租)
|
|
|
|
// 计算租金
|
|
System.out.println("\n=== 计算租金 ===");
|
|
double rent = car1.calculateRent(5);
|
|
System.out.println("车辆 " + car1.getLicensePlate() + " 租赁5天,总租金:" + rent + " 元");
|
|
|
|
// 测试setDailyRent非法值
|
|
System.out.println("\n=== 测试日租金非法值 ===");
|
|
car1.setDailyRent(-100); // 非法值,提示错误
|
|
System.out.println("修改后日租金:" + car1.getDailyRent() + " 元/天");
|
|
|
|
// 测试静态变量
|
|
System.out.println("\n=== 车辆总数 ===");
|
|
System.out.println("当前系统中车辆总数:" + Car.getTotalCars() + " 辆");
|
|
}
|
|
}
|