/**
* 需求:1.设计汽车类,属性有车轮个数和车重,方法输出汽车的信息。
* 2.设计卡车子类,添加属性载重量,方法输出车的所有信息。
* 3.设计面包车子类,添加属性载客数,方法输出车的所有信息。
* 4.设计测试主类。
*/
package cn.com.qiche;
public class QiChe {
private int wheels;
private double weight;
public void setWheels(int wheels){
if(wheels>=4){
this.wheels=wheels;
}else{
System.out.println("请输入正确的车轮个数。");
}
}
public int getWheels(){
return wheels;
}
public void setWeight(double weight){
if(weight>0){
this.weight=weight;
}else{
System.out.println("车重应该是正数!!");
}
}
public double getWeight(){
return weight;
}
//输出车轮个数和车重
public void show(){
System.out.println("车轮个数:"+getWheels()+"\t车重:"+getWeight());
}
}
|
|