package TestRent;
import java.util.Scanner;
/**
* 计算汽车租赁的总租金。
*/
public class TestRent {
public static void main(String[] args) {
int days;// 租赁天数
int totalRent;// 总租赁费用
MotoVehicle motos[]=new MotoVehicle[5];
motos[0]=new Car("宝马x5","豫DX56432","1");
motos[1]=new Car("宝马x6","豫DX51112","2");
motos[2]=new Car("金龙","豫DX99832","3");
motos[3]=new Bus("别克林荫大道","豫DX99832",34);
motos[4]=new Truck("比亚迪","豫DX99832",8);
//控制台输入
//1、客户租赁的多辆汽车信息及租赁天数
Customer customer = new Customer("1","万方");
//2、计算总租赁费用
System.out.println("总租金为:"+customer.calcTotalRent(motos,5));
}
}
package TestRent;
/**
* 汽车抽象类。
*/
public abstract class MotoVehicle {
private String no;// 汽车牌号
private String brand;// 汽车品牌
/**
* 有参构造方法。
* @param no 汽车牌号
* @param brand 汽车品牌
*/
public MotoVehicle(String no, String brand) {
this.no = no;
this.brand = brand;
}
public String getNo() {
return no;
}
public String getBrand() {
return brand;
}
/**
* 抽象方法,计算汽车租赁价。
* */
public abstract int calRent(int days);
}
package TestRent;
/**
* 客户类。
*/
public class Customer {
String id;//客户编号
String name;//客户姓名
/**
* 有参构造方法。
* @param id 客户编号
* @param name 客户姓名
*/
public Customer(String id, String name) {
this.id=id;
this.name=name;
}
public String getId() {
return id;
}
public String getName() {
return name;
}
/**
* 计算多辆汽车总租赁价格
*/
public int calcTotalRent(MotoVehicle motos[],int days){
int sum=0;
for(int i=0;i<motos.length;i++)
sum+=motos[i].calRent(days);
return sum;
}
}
package TestRent;
/**
* 客车类,继承汽车类。
*/
public final class Bus extends MotoVehicle {
private int seatCount;// 座位数
/**
* 有参构造方法。
* @param no 汽车牌号
* @param brand 汽车品牌
* @param seatCount 座位数
*/
public Bus(String no, String brand, int seatCount) {
super(no, brand);
this.seatCount = seatCount;
}
public int getSeatCount() {
return seatCount;
}
/**
* 计算客车租赁价
*/
public int calRent(int days) {
if (seatCount <= 16) {
return days * 800;
} else {
return days * 1500;
}
}
}
package TestRent;
/**
* 轿车类,继承汽车类。
*/
public final class Car extends MotoVehicle {
private String type;// 汽车型号
/**
* 有参构造方法。
* @param no 汽车牌号
* @param brand 汽车品牌
* @param type 汽车型号
*/
public Car(String no, String brand, String type) {
super(no, brand);
this.type = type;
}
public String getType() {
return type;
}
/**
* 计算轿车租赁价
*/
public int calRent(int days) {
if ("1".equals(type)) {// 代表550i
return days * 500;
} else if ("2".equals(type)) {// 2代表商务舱GL8
return 600 * days;
} else {
return 300 * days;
}
}
}
package TestRent;
/**
* Created by Administrator on 2017/4/27.
*/
public final class Truck extends MotoVehicle {
int ton;
/**
* 有参构造方法。
*
* @param no 汽车牌号
* @param brand 汽车品牌
* ton 吨位
*/
public Truck(String no, String brand,int ton) {
super(no, brand);
this.ton=ton;
}
public int getTon(){
return ton;
}
/**
* 计算货车租赁价
*/
public int calRent(int days){
return days*50*ton;
}
}