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.

87 lines
2.1 KiB

package com.rental;
public class Car {
private String licensePlate;
private String brand;
private String model;
private double DailyRent;
private boolean isRented;
//构造静态变量totalcars
public static int totalcars=0;
//构造方法
public Car(String licensePlate,String brand,String model,double DailyRent){
this.licensePlate=licensePlate;
this.brand=brand;
this.model=model;
this.DailyRent=DailyRent;
this.isRented=false;
totalcars++;
}
public Car(){
this("FV 6666","Toyota","Nissan",500.0);
}
public Car(String licensePlate,String brand,String model){
this(licensePlate,brand,model,300.0);
}
//构造静态getTotalCars()方法
public static int getTotalcars(){
return totalcars;
}
//建立getter licensePlate brand model dailyRent isRented()method
public String getLicensePlate(){
return licensePlate;
}
public String getBrand(){
return brand;
}
public String getModel(){
return model;
}
public double getDailyRent() {
return DailyRent;
}
public boolean isRented(){
return isRented;
}
//建立setter
public void setBrand(String brand){
this.brand=brand;
}
public void setModel(String model) {
this.model = model;
}
public void setDailyRent(double DailyRent){
if (DailyRent>0){
this.DailyRent=DailyRent;
}
else{
System.out.println("非法租金,修改失败");
}
}
public void rentCar(){
if(isRented==true){
System.out.println("车辆已租出,无法再次租用");
}
else{
isRented=true;
}
}
public void returnCar(){
if(isRented==false){
System.out.println("车辆未被租用,无需归还");
}
else{
isRented=false;
}
}
public double calculateRent(int days){
double money=days*DailyRent;
return money;
}
}