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.
41 lines
1.5 KiB
41 lines
1.5 KiB
import com.rental.Car;
|
|
|
|
public class TestCar {
|
|
public static void main(String[] args) {
|
|
//创建至少3个Car对象
|
|
Car car1 = new Car("京A88888", "奥迪", "A6L", 500.0);
|
|
Car car2 = new Car("沪B66666", "宝马", "5系");
|
|
Car car3 = new Car("粤C12345", "奔驰", "E300L", 600.0);
|
|
|
|
//输出所有车辆信息
|
|
System.out.println("所有车辆信息如下");
|
|
car1.displayInfo();
|
|
car2.displayInfo();
|
|
car3.displayInfo();
|
|
System.out.println();
|
|
|
|
//对其中一辆车依次调用业务方法
|
|
System.out.println("对其中一辆车依次调用业务方法如下");
|
|
car1.rentCar(); // 第一次租用
|
|
car1.rentCar(); // 再次租用,查看提示
|
|
car1.returnCar(); // 第一次归还
|
|
car1.returnCar(); // 再次归还,查看提示
|
|
System.out.println();
|
|
|
|
//调用 calculateRent(5) 计算费用
|
|
System.out.println("调用 calculateRent(5) 计算某辆车租用 5 天的费用");
|
|
double rent5Days = car3.calculateRent(5);
|
|
System.out.println("车辆 " + car3.getLicensePlate() + " 租用5天的费用为: " + rent5Days + " 元");
|
|
System.out.println();
|
|
|
|
//尝试通过 setter 修改日租金为非法值
|
|
System.out.println("测试日租金合法性校验");
|
|
System.out.println("修改前 car2 的日租金: " + car2.getDailyRent());
|
|
car2.setDailyRent(-100); // 设置为非法值
|
|
System.out.println("修改后 car2 的日租金: " + car2.getDailyRent());
|
|
System.out.println();
|
|
|
|
//输出总车辆数
|
|
System.out.println("本次运行共创建了 " + Car.getTotalCars() + " 辆车。");
|
|
}
|
|
}
|