qq_一念执着_4
2016-03-09 23:19
======================================start=========================================
/**
*
* 哒哒租车系统<br>
* 车类,所有车的父类
*
* @author JohnNiang
* @version v1.0
*
*/
public abstract class Car {
// 定义成员变量
public String model; // 车型
public float price; // 车辆的租车价格
public boolean isRent = false; // 是否可租
// 成员函数
public Car() {
model = "null";
price = 0f;
isRent = false;
}
public Car(String model, float price, boolean isRent) {
this.model = model;
this.price = price;
this.isRent = isRent;
}
public abstract String getModel();
public abstract void setModel(String model);
public abstract float getPrice();
public abstract void setPrice(float price);
public abstract boolean getIsRent();
public abstract void setRent(boolean isRent);
@Override
public abstract String toString();
}
====================================================================================
/**
* 客车或小车类,继承车类
*
* @author JohnNiang
* @version v1.0
*/
public class Bus extends Car {
// 定义额外的成员变量
private int peoNum; // 客车特有的载客量
// 成员变量
public Bus() {
}
public Bus(String model, float price, boolean isRent, int peoNum) {
super(model, price, isRent);
this.peoNum = peoNum;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public float getPrice() {
return price;
}
public void setPrice(float price) {
this.price = price;
}
public boolean getIsRent() {
return isRent;
}
public void setRent(boolean isRent) {
this.isRent = isRent;
}
public void setPeoNum(int peoNum) {
this.peoNum = peoNum;
}
public int getPeoNum() {
return peoNum;
}
@Override
public String toString() {
if (isRent) {
return model + "\t\t" + price + "/天\t\t载人:" + peoNum
+ "人\t\t\t\t是";
} else {
return model + "\t\t" + price + "/天\t\t载人:" + peoNum
+ "人\t\t\t\t否";
}
}
}
=================================================================================
/**
* 卡车类,继承车类
*
* @author JohnNiang
* @version v1.0
*/
public class Trunk extends Car {
// 新增成员变量
private float loadNum; // 卡车特有的载货量
// 成员方法
public Trunk() {
}
public Trunk(String model, float price, boolean isRent, float loadNum) {
super(model, price, isRent);
this.loadNum = loadNum;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public float getPrice() {
return price;
}
public void setPrice(float price) {
this.price = price;
}
public boolean getIsRent() {
return isRent;
}
public void setRent(boolean isRent) {
this.isRent = isRent;
}
public void setLoadNum(float loadNum) {
this.loadNum = loadNum;
}
public float getLoadNum() {
return loadNum;
}
@Override
public String toString() {
if (isRent) {
return model + "\t\t" + price + "/天\t\t载货:" + loadNum
+ "吨\t\t\t是";
} else {
return model + "\t\t" + price + "/天\t\t载货:" + loadNum
+ "吨\t\t\t否";
}
}
}
==================================================================================
/**
* 皮卡车类,继承车类
*
* @author JohnNiang
* @version v1.0
*/
public class PickUp extends Car {
// 定义成员变量,皮卡同时可以载人,也可以载货
private float loadNum; // 载货量
private int peoNum; // 载人量
// 成员方法
public PickUp() {
}
public PickUp(String model, float price, boolean isRent, float loadNum,
int peoNum) {
super(model, price, isRent);
this.loadNum = loadNum;
this.peoNum = peoNum;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public float getPrice() {
return price;
}
public void setPrice(float price) {
this.price = price;
}
public boolean getIsRent() {
return isRent;
}
public void setRent(boolean isRent) {
this.isRent = isRent;
}
public void setLoadNum(float loadNum) {
this.loadNum = loadNum;
}
public float getLoadNum() {
return loadNum;
}
public void setPeoNum(int peoNum) {
this.peoNum = peoNum;
}
public int getPeoNum() {
return peoNum;
}
@Override
public String toString() {
if (isRent) {
return model + "\t\t" + price + "/天\t\t载人:" + peoNum
+ "人\n\t\t\t\t\t载货:" + loadNum + "吨\t\t\t是";
} else {
return model + "\t\t" + price + "/天\t\t载人:" + peoNum
+ "人\n\t\t\t\t\t载货:" + loadNum + "吨\t\t\t否";
}
}
}
==================================================================================
/**
*
* 哒哒租车系统<br>
* 车类,所有车的父类
*
* @author JohnNiang
* @version v1.0
*
*/
public abstract class Car {
// 定义成员变量
public String model; // 车型
public float price; // 车辆的租车价格
public boolean isRent = false; // 是否可租
// 成员函数
public Car() {
model = "null";
price = 0f;
isRent = false;
}
public Car(String model, float price, boolean isRent) {
this.model = model;
this.price = price;
this.isRent = isRent;
}
public abstract String getModel();
public abstract void setModel(String model);
public abstract float getPrice();
public abstract void setPrice(float price);
public abstract boolean getIsRent();
public abstract void setRent(boolean isRent);
@Override
public abstract String toString();
}
===================================end===========================================
看来是我点错了,这个原来是问问题的啊
Java入门第二季 升级版
530655 学习 · 6091 问题
相似问题