汽车租赁系统

Posted zxbaoer

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了汽车租赁系统相关的知识,希望对你有一定的参考价值。

package com.zuchexitong;
//汽车类
public abstract class QiCheLei {
    //车牌号  品牌 日租金
    private String chePaiHao;
    private String pinPai;
    private int riZuJin;
    
    public QiCheLei() {}
    
    public QiCheLei(String chePaiHao,String pinPai,int riZuJin) {
        this.chePaiHao = chePaiHao;
        this.pinPai = pinPai;
        this.riZuJin = riZuJin;
    }
    public String getChePaiHao() {
        return chePaiHao;
    }
    public void setChePaiHao(String chePaiHao) {
        this.chePaiHao = chePaiHao;
    }
    public String getPinPai() {
        return pinPai;
    }
    public void setPinpai(String pinpai) {
        this.pinPai = pinpai;
    }
    public int getRiZuJin() {
        return riZuJin;
    }
    public void setRiZuJin(int riZuJin) {
        this.riZuJin = riZuJin;
    }
    
    
    
    //计算租金  抽象方法
    public abstract float JiSuanZuJin(int days);
}

package com.zuchexitong;
//轿车类
public class Car extends QiCheLei {
    //    型号
    private String xingHao;
    
    public String getXingHao() {
        return xingHao;
    }
    
    public void setXingHao(String xingHao) {
        this.xingHao = xingHao;
    }
    
    public Car() {}
    
    public Car(String chePaiHao,String pinPai,int riZuJin,String xingHao) {
        super(chePaiHao,pinPai,riZuJin);
        this.xingHao = xingHao;
        
    }
    public float JiSuanZuJin(int days) {
        float price = this.getRiZuJin()*days;
        if(days>7 && days<=30) {
            price *= 0.9f;
        }else if(days>30 && days<=150) {
            price *=0.8f;
        }else if(days>150) {
            price *= 0.7f;
        }
        return price;
    }
}


package com.zuchexitong;
//客车类
public class Bus extends QiCheLei {
    //    座位上
    private int zuoWeiShu;
    
    public int getZuoWeiShu() {
        return zuoWeiShu;
    }
    public void setZuoWeiShu(int zuoWeiShu) {
        this.zuoWeiShu = zuoWeiShu;
    }
    
    public Bus() {}
    
    public Bus(String chePaiHao,String pinPai,int riZuJin,int zuoWeiShu) {
        super(chePaiHao,pinPai,riZuJin);
        this.zuoWeiShu = zuoWeiShu;
        
    }
    
    //重写父类的计算租金方法,根据自己租车天数计算租金
    public float JiSuanZuJin(int days) {
        float price = this.getRiZuJin()*days;
        if(days>=3 && days<=7) {
            price *= 0.9f;
        }else if(days>=7 && days<=30) {
            price *=0.8f;
        }else if(days>=30 && days<150) {
            price *= 0.7f;
        }else if(days>=150) {
            price *= 0.6f;
        }
        return price;
    }
}


package com.yewu;

import com.zuchexitong.Bus;
import com.zuchexitong.Car;
import com.zuchexitong.QiCheLei;

//汽车业务类
public class YeWuLei {
    //汽车类型的数组,该数组声明为父类类型
    public QiCheLei[] qiChes = new QiCheLei[8];
    //初始化汽车信息
    public void init() {
        qiChes[0] = new Car("京B45454","宝马",800,"X6");
        qiChes[1] = new Car("京L21254","宝马",600,"550i");
        qiChes[2] = new Car("京N32454","别克",300,"林萌大道");
        qiChes[3] = new Car("京R45234","别克",600,"X6");
        qiChes[4] = new Bus("京N33314","金杯",800,16);
        qiChes[5] = new Bus("京F32222","金杯",1500,36);
        qiChes[6] = new Bus("京N55554","金龙",800,16);
        qiChes[7] = new Bus("京N56666","金龙",1500,36);
    }
    
    //租车 :根据用户提供的条件去汽车数组中查找相应的车类并返回
    //如果租赁的是客车  条件是:品牌  座位数  -- 型号null
    //如果是客车   条件是:品牌 型号    --座位数0
    public QiCheLei zuChe(String pinPai,String xingHao,int zuoWeiShu) {
        QiCheLei qiChe = null;
        for(QiCheLei myQiChe:qiChes) {
            if(myQiChe instanceof Car) {
                Car car = (Car)myQiChe;
                if(car.getPinPai().equals(pinPai) && car.getXingHao().equals(xingHao)) {
                    qiChe = car;
                    break;
                }
            }else {
                Bus bus = (Bus)myQiChe;
                if(bus.getPinPai().equals(pinPai) && bus.getZuoWeiShu()==zuoWeiShu) {
                    qiChe = bus;
                    break;
                }
            }
            
        }
        return qiChe;
        
    }
}

package com.yewu;
//汽车租赁管理类  测试类
import java.util.Scanner;

import com.zuchexitong.QiCheLei;
public final class Sest {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        YeWuLei che = new YeWuLei();
        //租赁公司首先需要购置汽车
        che.init();
        System.out.println("**************欢迎光临租赁公司*****************");
        
        System.out.println("1、轿车	2客车");
        System.out.println("请选汽车类型");
        int type = input.nextInt();
        //客户租车条件
        String pinPai ="";//品牌
        String xingHao ="";//型号
        int zuoWeiShu = 0;//座位数
        //收集用户条件
        if(type == 1) {
            //租赁轿车
            System.out.println("请选择您要租的轿车品牌:1、别克 2宝马");
            int choose = input.nextInt();
            if(choose == 1) {
                pinPai = "别克";
                System.out.println("请选择汽车型号:1、林萌大道 2、GL8");
                xingHao = (input.nextInt() == 1)?"林萌大道":"GL8";
            }else if(choose == 2) {
                pinPai = "宝马";
                System.out.println("请选择汽车型号:1、X6 2、550i");
                xingHao = (input.nextInt() == 1)?"X6":"550i";
            }
        }else if(type == 2) {
            //租赁客车
            xingHao = "";
            System.out.println("请选汽车品牌:1、金杯 2、金龙");
            pinPai = (input.nextInt() == 1)?"金杯":"金龙";
            System.out.println("请选择您要组的客车座位数:1、16 2、36");
            zuoWeiShu = (input.nextInt() == 1)?16:36;
        }
        //租车
        QiCheLei myChe = che.zuChe(pinPai, xingHao, zuoWeiShu);
        System.out.println("请输入您租赁的天数:");
        int days = input.nextInt();
        float money = myChe.JiSuanZuJin(days);
        System.out.println("租车成功,按照如下车牌取车:"+myChe.getChePaiHao());
        System.out.println("您需要支付:"+money+"");
    }
}

技术图片

技术图片

 

以上是关于汽车租赁系统的主要内容,如果未能解决你的问题,请参考以下文章

为啥尽管源代码没有变化,但从一个系统到另一个系统的片段数量却有很大差异?

Verilog HDL 模拟 汽车尾灯自动控制系统

基于javaweb+jsp的汽车租赁管理系统

C#程序员经常用到的10个实用代码片段 - 操作系统

汽车电子控制系统各名称代码(英文缩写)是啥?

Java+SSM+Jsp+Mysql实现Web汽车信息管理系统