我这哪里出错了呀
package Test;
import imoocproject.Bicycle;
import imoocproject.Bicycle.ElectricVehicle;
import imoocproject.NonMotor;
import imoocproject.tricycle;
public class Test {
public static void main(String[] args) {
NonMotor Non=new NonMotor("天宇","红",4,2);
System.out.print("父类信息测试:"+Non.work());
Bicycle Bic=new Bicycle("捷安特","黄");
System.out.print("\n自行车类信息测试:"+Bic.work());
ElectricVehicle ev=new ElectricVehicle();
ev.setBatteryBrand("飞鸽");
System.out.print("\n电动车类信息测试:"+ev.work());
tricycle tri=new tricycle();
System.out.print("\n三轮车类信息测试:"+tri.work());
}
}
package imoocproject;
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) {
this.setBrand(brand);
this.setColor(color);
}
public NonMotor(String brand,String color,int wheel,int seat) {
this.setBrand(brand);
this.setColor(color);
this.setWheel(wheel);
this.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 work() {
String str="这是一辆"+this.getColor()+"颜色的,"+this.getBrand()+"牌的非机动车,有"+this.getWheel()+"个轮子,有"+this.getSeat()+"个座椅的非机动车。";
return str;
}
}
package imoocproject;
public class Bicycle extends NonMotor {
public class ElectricVehicle {
}
// 在构造方法中调用父类多参构造,完成属性赋值
public Bicycle(String brand,String color){
super(brand,color);
}
// 重写运行方法,描述内容为:这是一辆**颜色的,**牌的自行车。其中**的数据由属性提供
public String work() {
String str="这是一辆"+this.getColor()+"颜色的,"+this.getBrand()+"牌的自行车";
return str;
}
}
package imoocproject;
public class tricycle extends NonMotor {
// 在无参构造中实现对轮子属性值进行修改
public tricycle(){
this.setWheel(3);
}
// 重写运行方法,描述内容为:三轮车是一款有**个轮子的非机动车。其中**的数据由属性提供
public String work() {
String str="三轮车是一款有"+this.getWheel()+"个轮子的非机动车";
return str;
}
}
package imoocproject;
public class ElectricVehicle extends NonMotor {
// 私有属性:电池品牌
private String batteryBrand;
// 公有的get***/set***方法完成属性封装
public String getBatteryBrand(){
return batteryBrand;
}
public void setBatteryBrand(String batteryBrand){
this.batteryBrand=batteryBrand;
}
// 重写运行方法,描述内容为:这是一辆使用**牌电池的电动车。其中**的数据由属性提供
public String work() {
String str="这是一辆使用"+this.getBatteryBrand()+"牌电池的电动车";
return str;
}
}7
收起
正在回答 回答被采纳积分+1
1回答
2023版Java工程师
- 参与学习 人
- 提交作业 8788 份
- 解答问题 9886 个
综合就业常年第一,编程排行常年霸榜,北上广深月薪过万! 不需要基础,无需脱产即可学习,只要你有梦想,想高薪! 全新升级:技术栈升级(包含VUE3.0,ES6,Git)+项目升级(前后端联调与功能升级)
了解课程


恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星