汽车租赁系统V2.0

简单记录一下
代码如下

抽象类Vehicle

package RentCar;

public abstract class Vehicle {
    private String vehicleId;
    private String brand;
    private int perRent;

    public Vehicle() {
    }

    public Vehicle(String vehicleId, String brand, int perRent) {
        this.vehicleId = vehicleId;
        this.brand = brand;
        this.perRent = perRent;
    }

    public String getVehicleId() {
        return vehicleId;
    }

    public void setVehicleId(String vehicleId) {
        this.vehicleId = vehicleId;
    }

    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }

    public int getPerRent() {
        return perRent;
    }

    public void setPerRent(int perRent) {
        this.perRent = perRent;
    }

    public abstract float calRent(int days);
}

Bus类

package RentCar;

public class Bus extends Vehicle{
    private int seats;

    public Bus() {
    }

    public Bus(String vehicleId, String brand, int perRent, int seats) {
        super(vehicleId, brand, perRent);
        this.seats = seats;
    }

    public int getSeats() {
        return seats;
    }

    public void setSeats(int seats) {
        this.seats = seats;
    }

    @Override
    public float calRent(int days) {
        float money;
        if(days > 150) {
            money = getPerRent() * days * 6 / 10;
        }else if(days > 30){
            money = getPerRent() * days * 7 / 10;
        }else if(days >7) {
            money = getPerRent() * days * 8 / 10;
        }else if(days > 3){
            money = getPerRent() * days * 9 / 10;
        }
        else
            money = getPerRent() * days;
        return money;
    }
}

Car类

package RentCar;

public class Car extends Vehicle{
    private String type;

    public Car() {
    }

    public Car(String vehicleId, String brand, String type, int perRent) {
        super(vehicleId, brand, perRent);
        this.type = type;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    @Override
    public float calRent(int days) {
        float money;
        if(days > 150) {
            money = getPerRent() * days * 7 / 10;
        }else if(days > 30){
            money = getPerRent() * days * 8 / 10;
        }else if(days >7) {
            money = getPerRent() * days * 9 / 10;
        }else
            money = getPerRent() * days;
        return money;
    }
}

Trunk类

package RentCar;

public class Trunk extends Vehicle{
    int tonnage;  //吨位

    public Trunk() {
    }

    public Trunk(String vehicleId, String brand, int perRent, int tonnage) {
        super(vehicleId, brand, perRent);
        this.tonnage = tonnage;
    }

    public int getTonnage() {
        return tonnage;
    }

    public void setTonnage(int tonnage) {
        this.tonnage = tonnage;
    }

    @Override
    public float calRent(int days) {

        return days*getPerRent();
    }
}

RentMgrSys类

package RentCar;

import java.util.Scanner;

public class RentMgrSys {
    public static void main(String[] args) {
        Car car;
        Bus bus;
        Trunk trunk;
        String vehicleId, type, brand;
        int days,seats,tonnage;
        Scanner sc = new Scanner(System.in);
        System.out.println("1.轿车      2.客车     3.卡车");
        System.out.print("请选择你要租赁的汽车类型:");
        vehicleId = sc.next();
        if("1".equals(vehicleId)){
            System.out.println("1.宝马     2.别克");
            System.out.print("请选择你要租赁的轿车品牌:");
            brand = sc.next();
            if("1".equals(brand)){
                System.out.println("1.550i   2.X6");
                System.out.print("请选择你要租赁的轿车型号:");
                type = sc.next();
                if("1".equals(type)){
                    System.out.print("请输入您要租赁的天数:");
                    days = sc.nextInt();
                    System.out.println("分配给您的汽车牌号是: 京CNY3284");
                    car = new Car(vehicleId, brand, type, 600);
                    System.out.print("您需要支付的租赁费用是:"+
                            car.calRent(days)+"元");
                }
                else if("2".equals(type)){
                    System.out.print("请输入您要租赁的天数:");
                    days = sc.nextInt();
                    System.out.println("分配给您的汽车牌号是: 京NY28588");
                    car = new Car(vehicleId, brand, type, 800);
                    System.out.print("您需要支付的租赁费用是:"+
                            car.calRent(days)+"元");
                }
            }
            else if("2".equals(brand)){
                System.out.println("1.林荫大道   2.GL8");
                System.out.print("请选择你要租赁的轿车品牌:");
                type = sc.next();
                if("1".equals(type)){
                    System.out.print("请输入您要租赁的天数:");
                    days = sc.nextInt();
                    System.out.println("分配给您的汽车牌号是: 京NT37465");
                    car = new Car(vehicleId, brand, type, 300);
                    System.out.print("您需要支付的租赁费用是:"+
                            car.calRent(days)+"元。s");

                }
                else if("2".equals(type)){
                    System.out.print("请输入您要租赁的天数:");
                    days = sc.nextInt();
                    System.out.println("分配给您的汽车牌号是:  京NT96968 ");
                    car = new Car(vehicleId, brand, type, 600);
                    System.out.print("您需要支付的租赁费用是:"+
                            car.calRent(days)+"元");
                }
            }
        }
        else if("2".equals(vehicleId)) {
            System.out.println("1.金杯     2.金龙");
            System.out.print("请选择你要租赁的客车品牌:");
            brand = sc.next();
            if ("1".equals(brand)) {
                System.out.print("请输入客车的座位数:");
                seats = sc.nextInt();
                if (seats <= 16) {
                    System.out.print("请输入您要租赁的天数:");
                    days = sc.nextInt();
                    System.out.println("分配给您的汽车牌号是: 京6566754");
                    bus = new Bus(vehicleId, brand, 800, seats );
                    System.out.print("您需要支付的租赁费用是:" +
                            bus.calRent(days) + "元");
                } else {
                    int count1 = seats/16;
                    System.out.print("请输入您要租赁的天数:");
                    days = sc.nextInt();
                    System.out.println("分配给您的汽车牌号是: 京8696997");
                    bus = new Bus(vehicleId, brand, 800, seats);
                    System.out.print("您需要支付的租赁费用是:" +count1*
                            bus.calRent(days) + "元");
                }
            }
            else if("2".equals(brand)){
                System.out.print("请输入客车的座位数:");
                seats = sc.nextInt();
                if (seats <= 34) {
                    System.out.print("请输入您要租赁的天数:");
                    days = sc.nextInt();
                    System.out.println("分配给您的汽车牌号是: 京9696996");
                    bus = new Bus(vehicleId, brand, 1500,seats);
                    System.out.print("您需要支付的租赁费用是:" +
                            bus.calRent(days) + "元");
                } else {
                    int count2 = seats/34;
                    System.out.print("请输入您要租赁的天数:");
                    days = sc.nextInt();
                    System.out.println("分配给您的汽车牌号是: 京8696998");
                    bus = new Bus(vehicleId, brand, 1500, seats);
                    System.out.print("您需要支付的租赁费用是:" +count2*
                            bus.calRent(days) + "元");
                }
            }
        }
        else if("3".equals(vehicleId)){
            System.out.println("1.解放     2.东风");
            System.out.print("请选择你要租赁的卡车品牌:");
            brand = sc.next();
            if ("1".equals(brand)) {
                System.out.print("请输入需要的卡车吨数:");
                tonnage = sc.nextInt();
                System.out.print("请输入您要租赁的天数:");
                days = sc.nextInt();
                System.out.println("分配给您的汽车牌号是: 京JF654321");
                trunk = new Trunk(vehicleId, brand, 50, tonnage ); //解放卡车每吨每天50元
                System.out.print("您需要支付的租赁费用是:" +
                        tonnage*trunk.calRent(days) + "元");
            }
            else if("2".equals(brand)){
                System.out.print("请输入需要的卡车吨数:");
                tonnage = sc.nextInt();
                System.out.print("请输入您要租赁的天数:");
                days = sc.nextInt();
                System.out.println("分配给您的汽车牌号是: 京DF123456");
                trunk = new Trunk(vehicleId, brand, 60, tonnage); //东风卡车每吨每天60元
                System.out.print("您需要支付的租赁费用是:" +
                        tonnage*trunk.calRent(days) + "元");
            }

        }
    }

}
  • 2
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值