2021-03-06车的租金

我的 三儿子


01

/*

Vehicle

*/

public class Vehicle {

//

  private String brand;//品牌

  private String licensePlateNumber;//车牌号

//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();

}

//计算总租金

public double getSumRent(int days){

return 0.0;

}

}



02


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();

}

//计算租金

public double getSumRent(int days){

if("两厢".equals(models)){

return 300 * days;

}else if("三厢".equals(models)){

return 350 * days;

}else{

return 500 * days;

}

}

}




02


03

/*

多座汽车类 Bus 是 Vehicle 的子

类,属性:座位数,座位数<=16 的每天 400,座位数>16 的每天 600。

*/

public class Bus extends Vehicle

{

//座位数,座位数<=16 的每天 400,座位数>16 的每天 600。

private int seats;

//set void 有参 this

public void setSeats(int seats){

this.seats=seats;

}

//

public int getSeats(){

return seats;

}

public Bus(){

super();

}

//计算租金

public double getSumRent(int days){

if(seats<=16){

return 400*days;

}else{

return 600*days;

}

}

}



03


03.

/*

计算汽车租金 Vehicle 是所有车的父类,属性:品牌、车牌号,有返回总租金的方法:public

double getSumRent(int days){} 小轿车类 Car 是 Vehicle 的子类,属性:车型(两厢、三厢、

越野),两厢每天 300,三厢每天 350,越野每天 500。 多座汽车类 Bus 是 Vehicle 的子

类,属性:座位数,座位数<=16 的每天 400,座位数>16 的每天 600。 编写测试类,根

据用户选择不同的汽车,计算总租金。

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()+"汽车,车牌号"+e.getLicensePlateNumber()+",10天总租金"+e.getSumRent(10));

    //

Bus b=new Bus();

b.setBrand("林坑金龙");

b.setLicensePlateNumber("京A 86668");

b.setSeats(60);

System.out.println("品牌: " + b.getBrand() + ",车牌号: " +

b.getLicensePlateNumber() + ",10 天总租金:" + b.getSumRent(10));

}

}





02



©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容