老师麻烦看看有需要修改的没?

来源:2-23 编程练习

渣娃小钻风

2020-03-05 17:30:52

package pers.apollo.test;

public class NonMotor {
private String brand;
private String color;
private int wheel = 2;
private int seat = 1;

public NonMotor() {
}

public NonMotor(String brand, String color) {
setBrand(brand);
setColor(color);
}

public NonMotor(String brand, String color, int wheel, int seat) {
setBrand(brand);
setColor(color);
setWheel(wheel);
setSeat(seat);
}

public String getBrand() {
return brand;
}

public void setBrand(String brand) {
this.brand = brand;
}

public String getColor() {
return color;
}

public void setColor(String color) {
this.color = color;
}

public int getWheel() {
return wheel;
}

public void setWheel(int wheel) {
this.wheel = wheel;
}

public int getSeat() {
return seat;
}

public void setSeat(int seat) {
this.seat = seat;
}

public String run() {
String str = "这是一辆" + getColor() + "颜色的," + getBrand() + "牌的非机动车,有" + getWheel() + "个轮子,有" + getSeat()
+ "个座椅的非机动车";
return str;
}
}
package pers.apollo.test;

public class Bicycle extends NonMotor {

public Bicycle() {

super("捷安特", "黄");

}

public String run() {

String str = "这是一辆" + super.getColor() + "颜色的," + super.getBrand() + "牌的自行车";
return str;
}

}
package pers.apollo.test;

public class Electric extends NonMotor {
private String battery;

public Electric() {}

public Electric(String battery) {
setBattery(battery);
}

public String getBattery() {
return battery;
}

public void setBattery(String battery) {
this.battery = battery;
}

public String run() {
String str="这是一辆使用"+getBattery()+"牌电池的电动车。";
return str;

}
}
package pers.apollo.test;

public class Tricycle extends NonMotor {
public Tricycle() {
setWheel(3);
}

public String run() {
String str = "三轮车是一款有" + getWheel() + "个轮子的非机动车。";
return str;
}
}
package pers.apollo.test;

public class Test {

public static void main(String[] args) {
NonMotor total = new NonMotor("天宇", "红", 4, 2);
System.out.println("父类信息测试:" + total.run());

Bicycle bic = new Bicycle();
System.out.println("自行车类信息测试:" + bic.run());

Electric ele = new Electric("飞鸽");
System.out.println("电动车类信息测试:" + ele.run());

Tricycle tri = new Tricycle();
System.out.println("电动车类信息测试:" + tri.run());

}

}

写回答

1回答

好帮手慕小脸

2020-03-05

同学你好,代码完成的很好,逻辑清晰~不需要修改了

如果我的回答解决了你的疑惑,请采纳!祝学习愉快!

0

0 学习 · 11489 问题

查看课程