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.6 KiB
41 lines
1.6 KiB
package com.rental;
|
|
public class TestCar {
|
|
public static void main(String[] args) {
|
|
// 构造方法
|
|
Car car1 = new Car("A123", "Toyota", "Camry", 300);
|
|
Car car2 = new Car("B456", "Honda", "Civic"); // 默认租金
|
|
Car car3 = new Car("C789", "BMW", "X5", -100); // 非法租金测试
|
|
// 输出车辆信息
|
|
System.out.println("所有车辆信息:");
|
|
displayInfo(car1);
|
|
displayInfo(car2);
|
|
displayInfo(car3);
|
|
// 流程测试
|
|
System.out.println("租车流程测试:");
|
|
car1.rentCar(); // 第一次租
|
|
car1.rentCar(); // 再租
|
|
car1.returnCar(); // 第一次还
|
|
car1.returnCar(); // 再还
|
|
//计算租金
|
|
System.out.println("租金计算:");
|
|
double rent = car2.calculateRent(5);
|
|
System.out.println("car2 租用5天费用: " + rent);
|
|
// 非法租金
|
|
System.out.println("非法租金测试:");
|
|
car2.setdailyRent(-100); // 给一个非法值
|
|
System.out.println("car2 当前日租金: " + car2.getDailyRent());
|
|
|
|
// 输出总车辆数
|
|
System.out.println("总车辆数");
|
|
System.out.println("Total Cars: " + Car.getTotalCars());
|
|
}
|
|
//输出车辆信息
|
|
public static void displayInfo(Car car) {
|
|
System.out.println("车牌号: " + car.getLicensePlate());
|
|
System.out.println("品牌: " + car.getBrand());
|
|
System.out.println("型号: " + car.getModel());
|
|
System.out.println("日租金: " + car.getDailyRent());
|
|
System.out.println("是否已租出: " + (car.isRented() ? "是" : "否"));
|
|
}
|
|
}
|
|
|
|
|