From c8a4524772d1ce2fa7877eac184ecbe12e52dcfc Mon Sep 17 00:00:00 2001 From: JiangYouhan <3080587852@qq.com> Date: Sun, 22 Mar 2026 17:32:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=20'w3/Car.java'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- w3/Car.java | 107 ---------------------------------------------------- 1 file changed, 107 deletions(-) delete mode 100644 w3/Car.java diff --git a/w3/Car.java b/w3/Car.java deleted file mode 100644 index ad8921a..0000000 --- a/w3/Car.java +++ /dev/null @@ -1,107 +0,0 @@ -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; - this.dailyRent = dailyRent; - this.isRented = false; // 初始化为未租出 - totalCars++; // 创建车辆时总数加1 - } - - // 三参构造方法(日租金使用默认值300) - public Car(String licensePlate, String brand, String model) { - this(licensePlate, brand, model, 300.0); // 调用全参构造 - } - - // Getter方法 - 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("错误:日租金必须大于0,保持原值:" + this.dailyRent); - } - } - - // 业务方法:租车 - public void rentCar() { - if (isRented) { - System.out.println("车辆已租出,无法再次租用"); - } else { - isRented = true; - System.out.println("车辆 " + licensePlate + " 租用成功"); - } - } - - // 业务方法:还车 - public void returnCar() { - if (!isRented) { - System.out.println("车辆未被租用,无需归还"); - } else { - isRented = false; - System.out.println("车辆 " + licensePlate + " 归还成功"); - } - } - - // 业务方法:计算租金 - public double calculateRent(int days) { - return dailyRent * days; - } - - // 显示车辆信息的方法 - public void displayInfo() { - System.out.println("========== 车辆信息 =========="); - System.out.println("车牌号:" + licensePlate); - System.out.println("品牌:" + brand); - System.out.println("型号:" + model); - System.out.println("日租金:" + dailyRent + "元/天"); - System.out.println("租出状态:" + (isRented ? "已租出" : "未租出")); - System.out.println("================================"); - } - - // 静态方法 - public static int getTotalCars() { - return totalCars; - } -}