JavaSE实现汽车租赁系统

用JavaSE阶段接口之前的知识完成一个简易的汽车租赁系统

汽车租赁系统信息表

在这里插入图片描述

运行结果

在这里插入图片描述
在这里插入图片描述

优化设计
  • 将汽车类设计为抽象类
  • 将计算租金的方法,设计为抽象方法
下面是代码:

汽车类

package CarRent;

/**
 * 汽车类
 */
public abstract class Vehicle {
    private String id;//车牌号
    private String brand;//品牌
    private int dayRent;//日租金

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    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;
    }

    public Vehicle(String id, String brand, int dayRent) {
        this.id = id;
        this.brand = brand;
        this.dayRent = dayRent;
    }

    //计算租金的方法
    public abstract double carRent(int days);
}

客车类

package CarRent;

/**
 * 客车类
 */
public class Bus extends Vehicle {
    private int seatCount;//座位数

    public int getSeatCount() {
        return seatCount;
    }

    public void setSeatCount(int seatCount) {
        this.seatCount = seatCount;
    }

    public Bus(String id, String brand, int seatCount, int dayRent) {
        super(id, brand, dayRent);
        this.seatCount = seatCount;
    }

    @Override
    public double carRent(int days) {//重写计算租金的方法
        if (days >= 1 && days <3) {
            System.out.println("不打折");
            return getDayRent() * days;
        }else if (days >= 3 && days <7){
            System.out.println("打9折");
            return getDayRent() * days * 0.9;
        }
        else if (days >= 7 && days <30){
            System.out.println("打8折");
            return getDayRent() * days * 0.8;
        }
        else if (days >= 30 && days <150){
            System.out.println("打7折");
            return getDayRent() * days * 0.7;
        }
        else if (days >= 150){
            System.out.println("打6折");
            return getDayRent() * days * 0.6;
       }
        return 0;
    }
}

轿车类

package CarRent;

/**
 * 轿车类
 */
public class Car extends Vehicle {
    private String type;//型号

    public String getType() {
        return type;
    }

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

    public Car(String id, String brand, String type, int dayRent) {
        super(id, brand, dayRent);
        this.type = type;
    }

    @Override
    public double carRent(int days) {//重写计算租金的方法
        if (days >= 1 && days <= 7) {
            System.out.println("不打折");
            return getDayRent() * days;
        }else if (days > 7 && days <= 30){
            System.out.println("打9折");
            return getDayRent() * days * 0.9;
        }
        else if (days >=30 && days <= 150){
            System.out.println("打8折");
            return getDayRent() * days * 0.8;
        }
        else if (days > 150){
            System.out.println("打7折");
            return getDayRent() * days * 0.7;
        }
        return 0;
    }
}

汽车业务类

package CarRent;

/**
 * 汽车业务类
 */
public class VehicleOperation {
    Vehicle[] vehicles = new Vehicle[8];//存储所有的车辆信息

    //车辆信息初始化
    public void initial(){
        vehicles[0] = new Car("京NY28558","宝马","X6",800);
        vehicles[1] = new Car("京CNY3284","宝马","550i",600);
        vehicles[2] = new Car("京NT37465","别克","林荫大道",300);
        vehicles[3] = new Car("京NT96968","别克","GL8",600);
        vehicles[4] = new Bus("京6566754","金杯",16,800);
        vehicles[5] = new Bus("京8696997","金龙",16,800);
        vehicles[6] = new Bus("京9696996","金杯",34,1500);
        vehicles[7] = new Bus("京8696998","金龙",34,1500);
    }
      //租赁汽车的办法
    public Vehicle getVehicle(String brand, String type,int seatCount) {
        //for循环遍历数组
        for(int i = 0; i< vehicles.length; i++){
            if (vehicles[i] instanceof Car) {
                // 强转成小汽车car
                Car car = (Car) vehicles[i];
                if (car.getBrand().equals(brand) && car.getType().equals(type)) {
                    return car;
                }
            }
            if(vehicles[i] instanceof Bus){
                // 强转成大客车Bus
                Bus bus = (Bus) vehicles[i];
                if (bus.getBrand().equals(brand) && bus.getSeatCount()==seatCount) {
                    return bus;
                }
            }
        }
        //如果没有就返回空
        return null;
    }
}

汽车租赁管理类
也是程序的入口

package CarRent;

/**
 * 汽车租赁管理类
 * 程序入口
 */

import java.util.Scanner;

public class TestRent {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        VehicleOperation vo = new VehicleOperation();//初始化
        vo.initial();

        //定义一个为空的容器
        Vehicle vehicle = null;

        System.out.println("--------欢迎光临秋名山守望者汽车租赁公司--------");
        System.out.println("1、轿车           2、客车");
        System.out.println("请输入你要租赁的汽车类型:");
        int num = sc.nextInt();
        if (num == 1) {
            System.out.println("请选择你要租赁的汽车品牌:1.别克  2.宝马");
            int brand = sc.nextInt();
            if (brand == 1) {
                System.out.println("请选择你要租赁的汽车类型:1、林荫大道  2、GL8");
                int type = sc.nextInt();
                if (type == 1) {
                    vehicle = vo.getVehicle("别克","林荫大道",4);
                }else if (type == 2) {
                    vehicle = vo.getVehicle("别克", "GL8", 4);
                }
            }else if (brand == 2) {
                System.out.println("请选择你要租赁的汽车类型:1、X6  2、550i");
                int type = sc.nextInt();
                if (type == 1) {
                    vehicle = vo.getVehicle("宝马","X6",4);
                }else if (type == 2) {
                    vehicle = vo.getVehicle("宝马", "550i", 4);
                }
            }
        }else if (num == 2) {
            System.out.println("请选择你要租赁的汽车品牌:1.金龙  2.金杯");
            int brand = sc.nextInt();
            if (brand == 1) {
                System.out.println("请选择你要租赁的汽车类型:1、16座  2、34座");
                int type = sc.nextInt();
                if (type == 1) {
                    vehicle = vo.getVehicle("金龙","",16);
                }else if (type == 2) {
                    vehicle = vo.getVehicle("金龙", "", 34);
                }
            }else if (brand == 2) {
                System.out.println("请选择你要租赁的汽车类型:1、16座  2、34座");
                int type = sc.nextInt();
                if (type == 1) {
                    vehicle = vo.getVehicle("金杯","",16);
                }else if (type == 2) {
                    vehicle = vo.getVehicle("金杯", "", 34);
                }
            }
        }
        if (vehicle != null) {
            System.out.println("请输入您的租车天数");
            int days =sc.nextInt();
            double money = vehicle.carRent(days);
            System.out.println("您租得的汽车牌号是" + vehicle.getId());
            System.out.println("您需要支付的租赁费用是" + money + "元");
        }else{
            System.out.println("抱歉,暂无您所需要的汽车类型,请重新选择");
        }
    }
}

程序运行结果:
在这里插入图片描述
在这里插入图片描述
写的不好,欢迎指点!
还请各路大神不吝赐教

  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
系统名称 汽车租赁系统 carRental 系统概要 汽车租赁系统总共分为两个大的模块,分别是系统模块和业务模块。其中系统模块和业务模块底下又有其子模块。 功能模块 一、业务模块 1、客户管理 客户列表 客户分页和模糊查询 客户添加、修改、删除 导出客户数据 2、车辆管理 车辆列表 车辆车辆分页和模糊查询 车辆添加、修改、删除 3、业务管理 汽车出租 1、根据客户身份证查询所有未出租的车辆信息 2、进行出租 出租单管理 1、多条件的模糊查询和分页 2、出租单的修改、删除、导出 汽车入库 检查单管理 1、多条件模糊查询和分页 2、检查单修改 3、导出检查单 4、统计分析 客户男女比例图 月出租量统计 销售员业绩统计 出租车辆类型统计 二、系统模块 1、用户登陆 校验用户名和密码 登陆成功将登陆信息写入登陆日志 未登录进行拦截 2、菜单管理 全查询菜单和根据左边的树查询不同菜单 菜单的添加、修改、删除 3、角色管理 全查询角色和模糊查询 角色的添加、修改、删除 4、用户管理 全查询用户和模糊查询 用户的添加、修改、删除以及重置密码 5、数据源的监控(druid monitor) 技术选型 后台技术选型 Spring SpringMVC Mybatis 前端技术选型 LayUI、dtree、echarts 开发环境 操作系统:Windows 10 编程语言:Java 开发工具:IDEA、Navicat、Git 项目构建:Maven 3.5.2 服务器:Tomcat 8.5 数据库:MySQL 代码托管平台:GitHub

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值