使用面向对象和集合实现汽车租赁系统

上代码

import java.util.Scanner;

class Car {
    private String plate;//车牌
    private String brand;//品牌
    private int dayrent;//日租金

    public Car(String plate, String brand, int dayrent) {
        this.plate = plate;
        this.brand = brand;
        this.dayrent = dayrent;
    }

    public Car() {
    }

    public String getPlate() {
        return plate;
    }

    public void setPlate(String plate) {
        this.plate = plate;
    }

    public String getBrand() {
        return brand;
    }

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

    public int getDayrent() {
        return dayrent;
    }

    public void setDayrent(int dayrent) {
        this.dayrent = dayrent;
    }
}

class jiaoCar extends car.Car {
    private String type;//型号
    private String arr[][];


    public jiaoCar(String plate, String brand, int dayrent,String type) {
        super(plate, brand, dayrent);
        this.type=type;
    }

    public jiaoCar() {

    }
    public void cost(){
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入您要租赁的天数");
        int days=sc.nextInt();
        System.out.println("分配给您的汽车牌号是:"+this.getPlate());
        if (days>7&&days<=30){
            System.out.println("您需要支付的费用是:"+days*0.9*this.getDayrent()+"元");
        }else if (days>30&&days<150){
            System.out.println("您需要支付的费用是:"+days*0.8*this.getDayrent()+"元");
        }else if (days>150){
            System.out.println("您需要支付的费用是:"+days*0.7*this.getDayrent()+"元");
        }else if (days>0&&days<=7){
            System.out.println("您需要支付的费用是:"+days*this.getDayrent()+"元");
        }else {
            System.out.println("输入错误,系统崩溃鸟!");
            return;
        }
    }
    public String getType() {
        return type;
    }

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

}

class keCar extends car.Car {
    private int seat;//座位数

    public keCar(String plate, String brand, int dayrent, int seat) {
        super(plate, brand, dayrent);
        this.seat = seat;
    }

    public void cost(){
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入您要租赁的天数");
        int days=sc.nextInt();
        System.out.println("分配给您的汽车牌号是:"+this.getPlate());
        if (days>7&&days<=30){
            System.out.println("您需要支付的费用是:"+days*0.8*this.getDayrent()+"元");
        }else if (days>30&&days<150){
            System.out.println("您需要支付的费用是:"+days*0.7*this.getDayrent()+"元");
        }else if (days>150){
            System.out.println("您需要支付的费用是:"+days*0.6*this.getDayrent()+"元");
        }else if (days>0&&days<=3){
            System.out.println("您需要支付的费用是:"+days*this.getDayrent()+"元");
        }else if (days>3&&days<=7){
            System.out.println("您需要支付的费用是:"+days*0.9*this.getDayrent()+"元");
        }
        else {
            System.out.println("输入错误,系统崩溃鸟!");
            return;
        }
    }
    public int getSeat() {
        return seat;
    }

    public void setSeat(int seat) {
        this.seat = seat;
    }
}

class Test {
    public static void main(String[] args) {
        car.jiaoCar[]a=new car.jiaoCar[4];
        a[0]= new car.jiaoCar("京NY28588", "宝马", 800, "X6");
        a[1]= new car.jiaoCar("京CNY3284", "宝马", 600, "550i");
        a[2]= new car.jiaoCar("京NT37465", "别克", 300, "林荫大道");
        a[3]= new car.jiaoCar("京NT96968", "别克", 600, "GL8");
        car.keCar[]b=new car.keCar[4];
        b[0]=new car.keCar("京6565655","金杯", 800,16);
        b[1]=new car.keCar("京1324678","金龙", 800,16);
        b[2]=new car.keCar("京4567521","金杯", 1500,34);
        b[3]=new car.keCar("京4567848","金龙", 1500,34);
        System.out.println("********************欢迎光临秋名山守望者汽车租赁公司*********************\n1、轿车 2、客车");
        Scanner sc=new Scanner(System.in);
        System.out.println("请选择你要租赁的汽车类型:");
        int type=sc.nextInt();
        if (type==1){
            System.out.println("请选择您要租赁的汽车品牌:\n1、别克 2、宝马");
            int brand=sc.nextInt();
            if (brand==2){
                System.out.println("请选择您要租赁的汽车型号:\n1、X6 2、550i");
                int type1=sc.nextInt();
                if (type1==1){//宝马X6
                    a[0].cost();
                }
                else if (type1==2){//宝马550i
                    a[1].cost();
                }
                else {
                    System.out.println("别瞎几把输");
                }
            }else if (brand==1){
                System.out.println("请选择您要租赁的汽车型号:\n1、林荫大道 2、GL8");
                int type1=sc.nextInt();
                if (type1==1){//别克林荫大道
                    a[2].cost();
                }
                else if (type1==2){//别克GL8
                    a[3].cost();
                }
                else {
                    System.out.println("别瞎几把输");
                }
            }else {
                System.out.println("别瞎几把输");
            }
        }else if (type==2){
            System.out.println("请选择您要租赁的客车品牌:\n1、金杯 2、金龙");
            int brand=sc.nextInt();
            if (brand==1){//金杯
                System.out.println("请选择您要租赁的客车座数:\n1、16座 2、34座");
                int type1=sc.nextInt();
                if (type1==1){//16座
                    b[0].cost();
                }
                else if (type1==2){//34座
                    b[2].cost();
                }
                else {
                    System.out.println("别瞎几把输");
                }
            }else if (brand==2){//金龙
                System.out.println("请选择您要租赁的客车座数:\n1、16座 2、34座");
                int type1=sc.nextInt();
                if (type1==1){//16座
                    b[1].cost();
                }
                else if (type1==2){//34座
                    b[3].cost();
                }
                else {
                    System.out.println("别瞎几把输");
                }
            }else {
                System.out.println("别瞎几把输");
            }
        }
    }
}
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值