JAVA-实现汽车租赁系统的计价功能

JAVA-实现汽车租赁系统的计价功能

1. MotoVehicleE

/**
 * @author Jensen
 * @data 2022/11/4
 * @usage
 */
public abstract class MotoVehicleE {
    private String no;
    private String brand;

    /**
     * 无参构造方法。
      */
    public MotoVehicleE(){}
    /**
     * 有参构造方法。
     * no ; 汽车牌号
     * brand ; 汽车品牌
     */
    public MotoVehicleE(String no, String brand){
        this.no = no;
        this.brand = brand;
    }

    /**
     * 租赁天数
     * @param days
     * @return
     */
    public abstract int callRent(int days);

}

2. CarE Class

/**
 * @author Jensen
 * @data 2022/11/4
 * @usage
 */
public final class CarE extends MotoVehicleE{
    private String type;

    /**
     * 无参构造方法
     */
    public CarE(){}

    public CarE(String type,String no, String brand){
        super(no,brand);
        this.type = type;
    }

    /**
     * 获取车辆类型
     * @param type
     */
    public void setType(String type){
        this.type = type;
    }
    public String getType() {
        return type;
    }
    /**
     * 这里的callRent只要继承了就是必须要强制重写的
     * @param days
     * @return
     */
    @Override
    public int callRent(int days){
        if ("1".equals(type)){
            return days * 500;
        } else if ("2".equals(type)) {
            return days * 600;
        }else {
            return days * 300;
        }
    }
}

3. BusE Class

/**
 * @author Jensen
 * @data 2022/11/4
 * @usage
 */
public final class BusE extends MotoVehicleE{
    private int seatCount;

    /**
     * 无参构造方法
     */
    public BusE(){}

    /**
     * 这里是有参构造方法
     * @param seatCount
     * @param brand
     * @param no
     */
    public BusE(int seatCount,String brand, String no){
        super(brand, no);
        this.seatCount = seatCount;
    }


    /**
     * 设置座位数
     * @param seatCount
     */
    public void setSeatCount(int seatCount){
        this.seatCount = seatCount;
    }
    public int getSeatCount() {
        return seatCount;
    }



    /**
     * 这里的callRent只要继承了就是必须要强制重写的
     * @param days
     * @return
     */
    @Override
    public int callRent(int days) {
        if (seatCount <= 15 ){
            return days*800;
        }else {
            return days*1500;
        }
    }
}

4. TestRentE Class

import java.util.Random;
import java.util.Scanner;

/**
 * @author Jensen
 * {@code @data} 2022/11/4
 */
public class TestRentE {
    public static Random random = new Random();
    public static final Scanner scanner = new Scanner(System.in);


    public static String getCarNumber(){
        StringBuilder sb = new StringBuilder("粤B");
        for (int i = 0; i<5;i++){
            if(random.nextInt(2)==0){
                sb.append((char)(random.nextInt(26)+65));
            }else {
                sb.append(random.nextInt(10));
            }
        }
        return sb.toString();
    }

    public static void start(){
        System.out.println(">>>欢迎您来到汽车租赁公司: ");
        System.out.println(">>>请输入要租几天: ");
        int days = scanner.nextInt();
        System.out.println(">>>请输入租赁汽车类型: \n1.轿车\t2.客车");
        String carType = scanner.next();
        int rent;
        if ("1".equals(carType)){
            System.out.println("1. 宝马\t2. 别克");
            String brand = scanner.next();
            String type;
            if ("1".equals(brand)){
                System.out.println(">>>您选择的型号是: 530i");
                type = "宝马-530i";
            }else {
                System.out.println("2.商务舱GL8 \t 3. 林荫大道");
                type = scanner.next();
            }
            String no = getCarNumber();
            System.out.println(">>>给您分配的汽车牌号是: "+no);
            MotoVehicleE carE = new CarE(type,no,brand);
            rent = carE.callRent(days);
        }else {
            System.out.println(">>>请输入租赁客车的品牌: \n1.金杯\t2.金龙");
            String brand = scanner.next();
            System.out.println(">>>请输入需要座位数量: ");
            int seatCount = scanner.nextInt();
            String no = getCarNumber();
            MotoVehicleE busE = new BusE(seatCount,brand,no);
            rent = busE.callRent(days);
            System.out.println(">>>给您分配的汽车牌号是: "+no);
        }
        System.out.println("\n顾客您好,你需要支付的租赁费用是: "+rent+".");
    }
    public static void main(String[] args) {
        start();
    }
}

总结

  1. 这里面还是有很多问题和缺陷,只是记录一下作业学习
  2. 参考文献:
    https://blog.csdn.net/qq_29163727/article/details/115079357?spm=1001.2014.3001.5506
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值