我的?三兒子
【
/*
Vehicle
*/
public class Vehicle {
//
? private String brand;//品牌
? private String licensePlateNumber;//車牌號(hào)
//get set
? public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
//
public String getLicensePlateNumber() {
return licensePlateNumber;
}
public void setLicensePlateNumber(String licensePlateNumber) {
this.licensePlateNumber = licensePlateNumber;
}
//
public Vehicle() {
super();
}
//計(jì)算總租金
public double getSumRent(int days){
return 0.0;
}
}
】
02
/*
Car
*/
public class Car extends Vehicle {
//車型:兩廂(300/天)、三廂(350/天)声登、越野(500/天)
private String models;
//
public String getModels() {
return models;
}
//
public void setModels(String models) {
this.models = models;
}
//
public Car() {
super();
}
//計(jì)算租金
public double getSumRent(int days){
if("兩廂".equals(models)){
return 300 * days;
}else if("三廂".equals(models)){
return 350 * days;
}else{
return 500 * days;
}
}
}
02
/*
多座汽車類 Bus 是 Vehicle 的子
類狠鸳,屬性:座位數(shù),座位數(shù)<=16 的每天 400捌刮,座位數(shù)>16 的每天 600碰煌。
*/
public class Bus extends Vehicle
{
//座位數(shù),座位數(shù)<=16 的每天 400绅作,座位數(shù)>16 的每天 600芦圾。
private int seats;
//set void 有參 this
public void setSeats(int seats){
this.seats=seats;
}
//
public int getSeats(){
return seats;
}
public Bus(){
super();
}
//計(jì)算租金
public double getSumRent(int days){
if(seats<=16){
return 400*days;
}else{
return 600*days;
}
}
}
03.
【
/*
計(jì)算汽車租金 Vehicle 是所有車的父類,屬性:品牌俄认、車牌號(hào)个少,有返回總租金的方法:public
double getSumRent(int days){} 小轎車類 Car 是 Vehicle 的子類洪乍,屬性:車型(兩廂、三廂夜焦、
越野)壳澳,兩廂每天 300,三廂每天 350茫经,越野每天 500巷波。 多座汽車類 Bus 是 Vehicle 的子
類,屬性:座位數(shù)卸伞,座位數(shù)<=16 的每天 400抹镊,座位數(shù)>16 的每天 600。 編寫(xiě)測(cè)試類荤傲,根
據(jù)用戶選擇不同的汽車垮耳,計(jì)算總租金。
Vehicle
Car
Bus
*/
public class Test
{
public static void main(String[] args){
Car e=new Car();
e.setBrand("bma寶馬");
e.setLicensePlateNumber("鄂A 88888");
e.setModels("三廂");
S.p(e.getBrand()+"汽車遂黍,車牌號(hào)"+e.getLicensePlateNumber()+",10天總租金"+e.getSumRent(10));
? ? //
Bus b=new Bus();
b.setBrand("林坑金龍");
b.setLicensePlateNumber("京A 86668");
b.setSeats(60);
System.out.println("品牌: " + b.getBrand() + "终佛,車牌號(hào): " +
b.getLicensePlateNumber() + ",10 天總租金:" + b.getSumRent(10));
}
}
】
02