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.
40 lines
1.8 KiB
40 lines
1.8 KiB
package com.rental;
|
|
|
|
public class TestCar {
|
|
//编写静态方法displayInfo()打印车辆信息
|
|
public static void displayInfo(Car car){ //static是声明静态
|
|
System.out.println("车辆信息:车牌号"+car.getLicensePlate()+" 品牌"+car.getBrand()+" 型号"+car.getModel()+" 日租金(元/天)"+car.getDailyRent());
|
|
}
|
|
public static void main(String[] args){
|
|
Car mine1=new Car("FU 0001","Crown","Wilsaf",200.0);
|
|
Car mine2=new Car("FU 8888","Toyota","Alpha");
|
|
Car mine3=new Car();
|
|
displayInfo(mine1);
|
|
displayInfo(mine2);
|
|
displayInfo(mine3);
|
|
//调用两次rentCar()并查看提示
|
|
System.out.println("--调用两次rentCar()并查看提示--");
|
|
mine1.rentCar();
|
|
System.out.println(mine1.isRented());
|
|
mine1.rentCar();
|
|
//调用两次returnCar()并查看提示
|
|
System.out.println("--调用两次returnCar()并查看提示--");
|
|
mine1.returnCar();
|
|
System.out.println(mine1.isRented());
|
|
mine1.returnCar();
|
|
//计算5天的租金
|
|
System.out.println("--计算5天的租金--");
|
|
System.out.println("您的总租金为:"+mine1.calculateRent(5)+"元");
|
|
//用setter修改租金为-100查看提示
|
|
System.out.println("--用setter修改租金为-100查看提示--");
|
|
System.out.println("当前日租金为:"+mine1.getDailyRent()+"元");
|
|
mine1.setDailyRent(-100);
|
|
//查看日租金是否保持原值
|
|
System.out.println("--查看日租金是否保持原值--");
|
|
System.out.println("当前日租金为:"+mine1.getDailyRent()+"元");
|
|
//输出车辆总数
|
|
System.out.println("--输出车辆总数--");
|
|
System.out.println("车辆总数为:"+Car.getTotalcars());
|
|
}
|
|
}
|
|
|
|
|