/*
某汽车租借公司有多种汽车可以出租,计算汽车的租金
Vehicle是所有车的父类,属性:品牌,车牌号
方法:返回总租金的方法:public double getSumRent(int days){}
Car:小轿车 属性:车型(两厢,三厢,越野)
两厢:每天300 三厢:每天400 越野:每天500
Bus:多座位汽车 属性:座位数
8<座位数<=16:每天400
座位数>16:每天600
测试类:根据用户选择不同的车,计算总租金并输出
*/
package day_6;
public class Vehicle {
private String brand;
private String id;
public Vehicle(){
}
public Vehicle(String brand,String id){
this.brand=brand;
this.id=id;
}
public double getSumRent(int days){
return 0;
}
}
package day_6;
public class Car extends Vehicle {
private String type;
public Car(){ //编写无参构造方法
}
public Car(String type){ //编写带参构造方法
this.type=type;
}
public double getSumRent(int days){ //对父类的getSumRent方法进行重写
switch (this.type){
case "两厢":
return 300*days;
case "三厢":
return 400*days;
case "越野":
return 500*days;
}
return 0;
}
}
package day_6;
public class Bus extends Vehicle {
private int seats;
public Bus(){
}
public Bus(int seats){
this.seats=seats;
}
public double getSumRent(int days){
if(days<=16 && days>8){
return 400*days;
}
else
return 600*days;
}
}
package day_6;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("请输入小轿车车的型号和租的天数:");
Car car = new Car(input.next());
System.out.println("总租金是:"+ car.getSumRent(input.nextInt()));
System.out.println("******************************************");
System.out.print("请输入多座位车的座位数和租的天数:");
Bus bus=new Bus(input.nextInt());
System.out.println("总租金是:"+ bus.getSumRent(input.nextInt()));
}
}