java汽车租赁系统代码

来源:互联网 发布:吉林省财政厅网络完全 编辑:程序博客网 时间:2024/05/01 09:17

简述

大一时候的实训项目。
java汽车租赁系统代码
运行结果:

控制台:

这里写图片描述

这里写图片描述

这里写图片描述

以上是全部的执行效果。

分析

我是以数组的形式存储汽车:

public class Car {    String[ ] name = new String[50];     int[ ] state = new int[50];     String[ ] date=new String[50];     int[] count=new int[50];     Scanner in=new Scanner(System.in);     int xuhao;     int k=3;     boolean flag=true;     public Car(){        ...    }

对原本系统里面的数先设定:

// 初始化程序     //数组初始化    public void Car(){         this.name[0]="宝马5i";         this.state[0]=0;          this.date[0]="2017-03-01";         this.name[1]="奔驰商务";         this.state[1]=1;        this.name[2]="大众Qolf";         this.state[2]=1;         this.name[3]="奇瑞艾5";         this.state[3]=0;         this.date[3]="2017-03-06"; 

随后,方法里面,用switch的方式 方便系统运行。

//菜单    void caidan(){         System.out.println("欢迎使用汽车出租管理系统");        System.out.println("----------------------------");        System.out.println("1.新增CAR");        System.out.println("2.查看CAR");        System.out.println("3.删除CAR");        System.out.println("4.借出CAR");        System.out.println("5.归还CAR");        System.out.println("6.退        出");        System.out.println("----------------------------");        System.out.println("请选择:");        //选择        xuhao=in.nextInt();         switch(xuhao){         case 1:            this.zengjia();            break;         case 2:            this.chakan();            break;         case 3:            this.shanchu();            break;         case 4:            this.jiechu();            break;         case 5:            this.guihuan();            break;         case 6:            this.tuichu();            break;         default:System.out.print("对不起,您的输入有误!请输入1—6:");         }    }

这样就可以在程序界面更加直观,代码就更加简洁。

这段代码在程序运行的时候每输入一个值(调用),都会弹出来,按0返回,或按任意键重新输入。//返回    void fanhui(){        System.out.print("按任意数字重新输入;按0返回:");         xuhao=in.nextInt();         if(xuhao==0){             System.out.println("-------------------------------------");             this.caidan();         }         else{            this.zengjia();        }     }

其中一个动作–> 归还

//归还    void guihuan(){        System.out.println("归还");        System.out.println("********欢迎进入还CAR页面******************");        System.out.println("请输入还CAR的名称:");        Scanner input = new Scanner(System.in);        double  price = 0.0;        String name = input.next();        for(int i = 0;i<this.name.length;i++){            if(this.name[i]!=null){ //有                if(this.name[i].equalsIgnoreCase(name) && this.state[i] == 0){ //以借出就可以归还                    this.state[i] = 1;                    System.out.println("请输入归还车的时间(年-月-日):");                    Scanner inputDate = new Scanner(System.in);                    //获取时间差                    long charge = charge1(this.date[i],inputDate.next());                    price = charge * 1;                    System.out.println(this.name[i]+"归还成功");                    System.out.println("您应付"+price+"元");                    //清空时间                    this.date[i] = null;                    break;                }            }else{                System.out.println("没有找到匹配的信息");                break;            }        }

//测试类    public static void main(String[] args) {        Car c=new Car();        c.Car();        c.caidan();    }

相关Car的代码已经发在github上了。

https://github.com/Liumce/Car.git

有什么问题请多指教!