package carrental;
public class Car extends Vehicle {
//出租车
public Car() {
super();
}
public Car(double rent, int seats, String load) {
super(rent, seats, load);
}
public void calcRent(int days) {
if(days >= 3 && days < 7){
double rent =days * this.getRent() * 0.9;
this.setRent(rent);
}else if(days > 7){
double rent = days * this.getRent() * 0.8;
this.setRent(rent);
}else if(days > 0 && days < 3){
this.setRent(days * this.getRent());
}
}
public void show() {
System.out.println("租金 :"+this.getRent()+"载人 :"+this.getSeats()+"容量 :"+this.getLoad());
}
}
//测试方法,利用多态
import java.util.Scanner;
public class TestVegicle {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Vehicle[] arr = new Vehicle[6];
arr[0] = new Car(500, 4, "最多4人");
arr[1] = new Car(400, 4, "最多4人");
arr[2] = new Car(450, 4, "最多4人,最多载货2吨");
arr[3] = new Bus(800, 20, "最多20人");
arr[4] = new Van(400, 4, "最多4吨");
arr[5] = new Van(1000, 20, "最多20吨");
System.out.println("欢迎使用租车系统你是否要租车:1是 0否 ");
System.out.println("您可租车的类型及其价目表 \r\n" + "序号:1 汽车名称:奥迪A4 租金500/天 容量:最多载人4人\r\n"
+ "序号:2 汽车名称:马自达6 租金400/天 容量:最多载人4人\r\n" + "序号: 3 汽车名称:皮卡雪6 租金450/天 容量:最多载人4人,最多载货2吨\r\n"
+ "序号:4 汽车名称:金龙 租金800/天 容量:最多载人20人 \r\n" + "序号:5 汽车名称:松花江 租金400/天 容量:最多载货4吨 \r\n"
+ "序号:6 汽车名称:依维柯 租金1000/天 容量:最多载货20吨 \r\n" + "请输入您要租车的序号和天数");
System.out.println("请输入您要租车的序号和天数:");
System.out.print("序号:");
int num = sc.nextInt();
num --;
System.out.print("天数:");
int day = sc.nextInt();
arr[num].calcRent(day);
arr[num--].show();
}
}