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.
34 lines
1.1 KiB
34 lines
1.1 KiB
public class TestCar {
|
|
public static void main(String[] args) {
|
|
// 创建3辆车,使用不同构造
|
|
Car car1 = new Car("京A12345", "丰田", "Camry", 280);
|
|
Car car2 = new Car("沪B67890", "大众", "Passat");
|
|
Car car3 = new Car("粤C98765", "宝马", "325i", 500);
|
|
|
|
// 打印信息
|
|
car1.displayInfo();
|
|
car2.displayInfo();
|
|
car3.displayInfo();
|
|
|
|
// 测试租车、重复租车、还车、重复还车
|
|
System.out.println("===测试car1租车还车===");
|
|
car1.rentCar();
|
|
car1.rentCar();
|
|
car1.returnCar();
|
|
car1.returnCar();
|
|
System.out.println();
|
|
|
|
// 计算5天租金
|
|
System.out.println("car2 租用5天租金:" + car2.calculateRent(5));
|
|
System.out.println();
|
|
|
|
// 测试非法租金
|
|
System.out.println("===尝试设置非法租金===");
|
|
car3.setDailyRent(-100);
|
|
System.out.println("设置后日租金:" + car3.getDailyRent());
|
|
System.out.println();
|
|
|
|
// 静态总数
|
|
System.out.println("当前车辆总数:" + Car.getTotalCars());
|
|
}
|
|
}
|