发布网友 发布时间:2022-04-23 06:16
共1个回答
热心网友 时间:2023-10-03 05:05
public class Vehicle {
private int speed;
private String brand;
private String no;
public Vehicle() {
}
public Vehicle(int speed, String brand, String no) {
this.speed = speed;
this.brand = brand;
this.no = no;
}
public int getSpeed() {
return speed;
}
public void setSpeed(int speed) {
this.speed = speed;
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public String getNo() {
return no;
}
public void setNo(String no) {
this.no = no;
}
public String showInfo() {
return "speed:" + speed + ",brand=" + brand + ",no=" + no;
}
public static void main(String[] args) {
Vehicle v1 = new Vehicle(150, "brand1", "123");
Vehicle v2 = new Vehicle(100, "brand2", "976");
Vehicle v3 = new Vehicle(200, "brand3", "231");
int averSpeed = (v1.speed + v2.speed + v3.speed) / 3;
System.out.println("三辆车的平均速度为:" + averSpeed);
}
}