package com.rental; public class Car { private final String licensePlate; private String brand; private String model; private double dailyRent; private boolean isRented; private static int totalCars=0; public Car(String licensePlate,String brand,String model,double dailyRent){ this.licensePlate=licensePlate; this.brand=brand; this.model=model; if (dailyRent > 0) { this.dailyRent = dailyRent; } else { this.dailyRent = 300; System.out.println("日租金不合法"); } this.isRented=false; Car.totalCars+=1; } public String getLicensePlate(){ return licensePlate; } public Car(String licensePlate, String brand, String model) { this(licensePlate, brand, model, 300); } public String getBrand(){ return brand; } public String getModel(){ return model; } public double getDailyRent(){ return dailyRent; } public boolean isRented() { return isRented; } 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){ System.out.println("车辆已租出,无法再次租用"); return; } this.isRented=true; } public void returnCar(){ if (!isRented){ System.out.println("车辆未被租用,无需归还"); return; } this.isRented=false; } public double calculateRent(int days){ return dailyRent*days; } public static int getTotalCars(){ return totalCars; } }