简易租车小练习(只写一个出租车)

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


}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值