package com.automobile.parts; /** * 车轮类 - 与汽车是组合关系 * 车轮是汽车的必要组成部分,不能独立于汽车存在 */ public class Wheel { private double diameter; private double width; private String brand; private double pressure; private boolean isMoving; /** * 构造方法 - 创建车轮时设置默认属性 */ public Wheel() { this.diameter = 17.0; // 英寸 this.width = 225.0; // 毫米 this.brand = "米其林"; this.pressure = 2.5; // 巴 this.isMoving = false; } /** * 开始转动 */ public void startMoving() { this.isMoving = true; System.out.println("车轮开始转动"); } /** * 停止转动 */ public void stopMoving() { this.isMoving = false; System.out.println("车轮停止转动"); } /** * 调整胎压 * @param newPressure 新的胎压值 */ public void adjustPressure(double newPressure) { if (newPressure >= 1.5 && newPressure <= 3.5) { this.pressure = newPressure; System.out.println("胎压调整到 " + newPressure + " 巴"); } else { System.out.println("无效的胎压值"); } } /** * 检查轮胎状态 */ public void checkStatus() { System.out.println("轮胎状态: 品牌=" + brand + ", 尺寸=" + diameter + "x" + width + ", 胎压=" + pressure + "巴, " + (isMoving ? "转动中" : "静止")); } // Getter 和 Setter 方法 public double getDiameter() { return diameter; } public void setDiameter(double diameter) { this.diameter = diameter; } public double getWidth() { return width; } public void setWidth(double width) { this.width = width; } public String getBrand() { return brand; } public void setBrand(String brand) { this.brand = brand; } public double getPressure() { return pressure; } public boolean isMoving() { return isMoving; } }