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

public class CarTest {
public static void main(String[] args) {
// 创建3个Car对象(使用不同构造方法)
Car car1 = new Car("京A12345", "丰田", "凯美瑞", 280.0);
Car car2 = new Car("沪B67890", "本田", "雅阁");
Car car3 = new Car("粤C13579", "大众", "帕萨特", 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 = car2.calculateRent(5);
System.out.println("车辆" + car2.getLicensePlate() + "租赁5天,总租金:" + rent + "元");
// 测试日租金非法值
System.out.println("\n=== 测试日租金非法值 ===");
car3.setDailyRent(-100); // 输入负数,提示错误
System.out.println("修改后日租金:" + car3.getDailyRent() + "元/天");
// 测试静态变量
System.out.println("\n=== 车辆总数统计 ===");
System.out.println("当前创建的车辆总数:" + Car.getTotalCars() + " 辆");
}
}