可以帮我看看有什么缺陷吗?

来源:2-22 编程练习

__Yang

2019-04-14 22:50:07

public class NonMotor {
	private String brand;
	private String colour;
	private int wheel;
	private int chair;
	
	public NonMotor() {
		
	}
	
	public NonMotor(String brand,String colour) {
		this.brand=brand;
		this.colour=colour;
	}
	
	public NonMotor(String brand,String colour,int wheel,int chair) {
		this.brand=brand;
		this.colour=colour;
		this.wheel=wheel;
		this.chair=chair;
	}
	
	public String getBrand() {
		return brand;
	}
	public void setBrand(String brand) {
		this.brand = brand;
	}
	public String getColour() {
		return colour;
	}
	public void setColour(String colour) {
		this.colour = colour;
	}
	public int getWheel() {
		return wheel;
	}
	public void setWheel(int wheel) {
		this.wheel = wheel;
	}
	public int getChair() {
		return chair;
	}
	public void setChair(int chair) {
		this.chair = chair;
	}
	
	public String work() {
		String str="这是一辆"+this.getBrand()+"颜色的,"+this.getColour()+
				   "牌的非机动车,有"+this.getWheel()+"个轮子,有"+this.getChair()+
				   "个座椅的非机动车。";
		return str;
	}
	
	

}
public class Bicycle extends NonMotor{
	public Bicycle() {
		
	}
	
	public Bicycle(String colour,String brand) {
		super(colour,brand);
	}
	
	public String work() {
		String str="这是一辆"+this.getBrand()+"颜色的,"+this.getColour()+"牌的自行车。";
		return str;
	}

}
public class ElectricVehicle extends NonMotor{
	private String batteryBrand="飞虎";
	public ElectricVehicle() {
		
	}
    public ElectricVehicle(String batteryBrand) {
		
	}
	public String getBatteryBrand() {
		return batteryBrand;
	}
	public void setBatteryBrand(String batteryBrand) {
		this.batteryBrand = batteryBrand;
	}

	public String work() {
		String str="这是一辆使用"+this.getBatteryBrand()+"牌电池的电动车。";
		return str;
	}
}
public class Tricycle extends NonMotor{
	public Tricycle() {
		this.setWheel(3);
	}

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

import com.imooc.animal.NonMotor;
import com.imooc.animal.Bicycle;
import com.imooc.animal.ElectricVehicle;
import com.imooc.animal.Tricycle;
public class Test22 {

	public static void main(String[] args) {
		NonMotor one=new NonMotor("红色","天宇",4,2);
		Bicycle two=new Bicycle("深蓝色","保时捷");
		ElectricVehicle three=new ElectricVehicle();
		Tricycle four=new Tricycle();
		System.out.print("父类信息测试:");
		System.out.println(one.work());
		System.out.print("自行车类信息测试:");
		System.out.println(two.work());
		System.out.print("电动车类信息测试:");
		System.out.println(three.work());
		System.out.print("三轮车类信息测试:");
		System.out.println(four.work());

	}

}


写回答

1回答

irista23

2019-04-15

程序有如下改进的地方:

1)按照效果图要求,需要在NonMotor类中去掉如下文字

http://img.mukewang.com/climg/5cb401060001c84606160109.jpg

2)注意题目效果中自行车要求输出的Bicycle two=new Bicycle("捷安特","黄");

http://img.mukewang.com/climg/5cb401ef00012fa403790030.jpg

3)测试类中ElectricVehicle要调用setBatteryBrand()来设置"飞鸽"品牌

0

0 学习 · 2907 问题

查看课程