学校作业,请忽略

Vehicle.java

package vehicles;

import java.util.Scanner;

public class RentMgrSys {
    public static void main(String[] args) {
        Car car;
        Bus bus;
        Trunk trunk;
        int vehicleId, type, brand, days, seats, tonnage;
        Scanner sc = new Scanner(System.in);
        System.out.println("********************欢迎来到优雅汽车租赁公司********************");
        System.out.println("1.轿车      2.客车     3.卡车\n请选择你要租赁的汽车类型:");
        vehicleId = sc.nextInt();
        switch (vehicleId) {
            case 1:
                System.out.println("1.宝马     2.别克\n请选择你要租赁的轿车品牌:");
                brand = sc.nextInt();
                if (brand == 1) {
                    System.out.println("1.550i   2.X6\n请选择你要租赁的轿车型号:");
                    type = sc.nextInt();
                    if (type == 1) {
                        System.out.print("请输入您要租赁的天数:");
                        days = sc.nextInt();
                        System.out.println("分配给您的汽车牌号是: 京CNY3284");
                        car = new Car("1", "1", 600, "1");
                        System.out.print("您需要支付的租赁费用是:" + car.calRent(days) + "元");
                        break;
                    } else if (type == 2) {
                        System.out.print("请输入您要租赁的天数:");
                        days = sc.nextInt();
                        System.out.println("分配给您的汽车牌号是: 京NY28588");
                        car = new Car("1", "1", 800, "2");
                        System.out.print("您需要支付的租赁费用是:" + car.calRent(days) + "元");
                        break;
                    }
                } else if (brand == 2) {
                    System.out.println("1.林荫大道   2.GL8\n请选择你要租赁的轿车型号:请选择你要租赁的轿车品牌:");
                    type = sc.nextInt();
                    if (type == 1) {
                        System.out.print("请输入您要租赁的天数:");
                        days = sc.nextInt();
                        System.out.println("分配给您的汽车牌号是: 京NT37465");
                        car = new Car("1", "2", 300, "1");
                        System.out.print("您需要支付的租赁费用是:" + car.calRent(days) + "元");
                        break;
                    } else if (type == 2) {
                        System.out.print("请输入您要租赁的天数:");
                        days = sc.nextInt();
                        System.out.println("分配给您的汽车牌号是: 京NT96968");
                        car = new Car("1", "2", 600, "2");
                        System.out.print("您需要支付的租赁费用是:" + car.calRent(days) + "元");
                        break;
                    }
                }
            case 2:
                System.out.println("1.金杯     2.金龙\n请选择你要租赁的客车品牌:");
                brand = sc.nextInt();
                if (brand == 1) {
                    System.out.print("请输入客车的座位数:");
                    seats = sc.nextInt();
                    if (seats <= 16) {
                        System.out.print("请输入您要租赁的天数:");
                        days = sc.nextInt();
                        System.out.println("分配给您的汽车牌号是: 京6566754");
                        bus = new Bus("2", "1", 800, seats);
                        System.out.print("您需要支付的租赁费用是:" + bus.calRent(days) + "元");
                    } else {
                        int count = seats / 16;
                        System.out.print("请输入您要租赁的天数:");
                        days = sc.nextInt();
                        System.out.println("分配给您的汽车牌号是: 京8696997");
                        bus = new Bus("2", "1", 800, seats);
                        System.out.print("您需要支付的租赁费用是:" + count * bus.calRent(days) + "元");
                    }
                    break;
                } else if (brand == 2) {
                    System.out.print("请输入客车的座位数:");
                    seats = sc.nextInt();
                    if (seats <= 34) {
                        System.out.print("请输入您要租赁的天数:");
                        days = sc.nextInt();
                        System.out.println("分配给您的汽车牌号是: 京9696996");
                        bus = new Bus("2", "2", 1500, seats);
                        System.out.print("您需要支付的租赁费用是:" + bus.calRent(days) + "元");
                    } else {
                        int count = seats / 34;
                        System.out.print("请输入您要租赁的天数:");
                        days = sc.nextInt();
                        System.out.println("分配给您的汽车牌号是: 京8696998");
                        bus = new Bus("2", "2", 1500, seats);
                        System.out.print("您需要支付的租赁费用是:" + count * bus.calRent(days) + "元");
                    }
                    break;
                }
            case 3:
                System.out.println("1.东风     2.重汽\n请选择你要租赁的卡车品牌:");
                brand = sc.nextInt();
                if (brand == 1) {
                    System.out.print("请输入需要的卡车吨数:");
                    tonnage = sc.nextInt();
                    System.out.print("请输入您要租赁的天数:");
                    days = sc.nextInt();
                    System.out.println("分配给您的汽车牌号是: 川AP097833");
                    trunk = new Trunk("3", "1", 60, tonnage);
                    System.out.print("您需要支付的租赁费用是:" + tonnage * trunk.calRent(days) + "元");
                } else if (brand == 2) {
                    System.out.print("请输入需要的卡车吨数:");
                    tonnage = sc.nextInt();
                    System.out.print("请输入您要租赁的天数:");
                    days = sc.nextInt();
                    System.out.println("分配给您的汽车牌号是: 川AQ985211");
                    trunk = new Trunk("3", "2", 60, tonnage);
                    System.out.print("您需要支付的租赁费用是:" + tonnage * trunk.calRent(days) + "元");
                }
                break;
        }
    }
}

Vehicle.java

package vehicles;

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

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

    public Vehicle() {
    }

    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.java

package vehicles;

public class Bus extends Vehicle {
    private int seats;

    public int getSeats() {
        return seats;
    }

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

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

    public Bus() {
    }

    @Override
    public float calRent(int days) {
        float total;
        if (days >= 150) {
            total = (float) (getPerRent() * days * 0.6);
        } else if (days >= 30) {
            total = (float) (getPerRent() * days * 0.7);
        } else if (days >= 7) {
            total = (float) (getPerRent() * days * 0.8);
        } else if (days >= 3) {
            total = (float) (getPerRent() * days * 0.9);
        } else
            total = getPerRent() * days;
        return total;
    }


}

Car.java

package vehicles;

public class Car extends Vehicle {
    private String type;

    public Car() {
    }

    public Car(String vehicleId, String brand, int perRent, String type) {
        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 total;
        if (days >= 150) {
            total = (float) (getPerRent() * days * 0.7);
        } else if (days >= 30) {
            total = (float) (getPerRent() * days * 0.8);
        } else if (days >= 7) {
            total = (float) (getPerRent() * days * 0.9);
        } else
            total = getPerRent() * days;
        return total;
    }
}

同Bus类

类图

Trunk.java

package vehicles;

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) {
        float total;
        if (days >= 150) {
            total = (float) (getPerRent() * days * 0.9);
        } else if (days >= 30) {
            total = (float) (getPerRent() * days * 0.9);
        } else
            total = getPerRent() * days;
        return total;
    }
}
最后修改:2022 年 10 月 12 日
如果觉得我的文章对你有用,请随意赞赏
本文作者:
文章标题:汽车租赁系统V2.0
本文地址:https://pysnow.cn/archives/504/
版权说明:若无注明,本文皆Pysnow's Blog原创,转载请保留文章出处。