用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;}@Overridepublic 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;}@Overridepublic 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) {// 强转成小汽车carCar car = (Car) vehicles[i];if (car.getBrand().equals(brand) && car.getType().equals(type)) {return car;}}if(vehicles[i] instanceof Bus){// 强转成大客车BusBus 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("抱歉,暂无您所需要的汽车类型,请重新选择");}}
}

程序运行结果:


写的不好,欢迎指点!
还请各路大神不吝赐教

JavaSE实现汽车租赁系统相关推荐

  1. 汽车租赁系统java窗口_共享型汽车租赁系统(SSM+MySql)

    知乎视频​www.zhihu.com 共享型汽车租赁系统(SSM+MySql)的设计与实现(毕业论文14000字以上,程序代码,MySQL数据库) [项目包含内容] [文档包含内容] [项目功能描述] ...

  2. 基于JAVA+SpringMVC+Mybatis+MYSQL的汽车租赁系统

    项目功能: 系统概要 汽车租赁系统总共分为两个大的模块,分别是系统模块和业务模块.其中系统模块和业务模块底下又有其子模块. 系统分为四类用户角色:超级管理员.业务管理员.系统管理员.数据统计管理员.角 ...

  3. JAVA汽车租赁系统(JAVA毕业设计)

    前言 课设毕设源码收集已上传到github,地址:https://github.com/52JDK/Source-Collection 如果对大家有用的话欢迎点个star,本文源码请直接到文章末尾 简 ...

  4. 租车汽车租赁系统开发

    租车汽车租赁系统开发 租车平台 在线益名 在线支付 一键续租 后台功能// 订单管理/ 待付款 待取车 待还车 订单管理 已完成 全部订单 车辆管理/ 添加车辆 已租车辆 待租车辆 仓库车辆 全部车辆 ...

  5. 基于JAVA汽车租赁系统计算机毕业设计源码+系统+lw文档+部署

    基于JAVA汽车租赁系统计算机毕业设计源码+系统+lw文档+部署 基于JAVA汽车租赁系统计算机毕业设计源码+系统+lw文档+部署 本源码技术栈: 项目架构:B/S架构 开发语言:Java语言 开发软 ...

  6. 基于JAVA汽车租赁系统计算机毕业设计源码+数据库+lw文档+系统+部署

    基于JAVA汽车租赁系统计算机毕业设计源码+数据库+lw文档+系统+部署 基于JAVA汽车租赁系统计算机毕业设计源码+数据库+lw文档+系统+部署 本源码技术栈: 项目架构:B/S架构 开发语言:Ja ...

  7. 汽车租赁系统(2)-完成登录功能

    文章目录 完成汽车租赁系统的登录功能 分析登录功能: 创建数据库的表 用户表(sys_users) 创建首页index.jsp 创建实体类 创建UserVo 创建Mapper 创建Mapper.xml ...

  8. 基于SSM的JSP MYSQL汽车租赁系统的汽车出租管理系统-mysqljava汽车出租管理系统租车管理系统

    基于SSM的JSP+MYSQL汽车租赁系统的汽车出租管理系统-mysqljava汽车出租管理系统租车管理系统 "基于SSM的汽车出租管理系统-mysql&java汽车出租管理系统租车 ...

  9. Swing + MySQL实现汽车租赁系统4.0

    Swing + MySQL实现汽车租赁系统4.0 引言 始 需求分析 系统功能结构图 类图 使用说明 部分代码 JDBC连接MySQL(需导入jar包) 登录界面 用户端界面 测试 用户注册 登录界面 ...

  10. 基于JAVA汽车租赁系统 (Springboot框架) 开题报告

      本科生毕业论文 基于Java(springboot框架)汽车租赁系统 开题报告 学    院: 专    业: 计算机科学与技术 年    级: 学生姓名: 指导教师:   XXXX大学本科生毕业 ...

最新文章

  1. ROM、RAM、IROM、IRAM、DRAM、SRAM、Flash介绍
  2. css面试基础知识,CSS知识点与面试题解析
  3. 项目中缺少maven dependencis,或者pom文件报红
  4. 所属的用户_关于chmod(变更用户对此文件的相关权限)超详细说明,小白秒懂
  5. [NOIP2016]愤怒的小鸟(状压DP)
  6. 【白皮书分享】2021年互联网人才招聘白皮书.pdf(附下载链接)
  7. 比尔盖茨:十条“金口玉言”-- 世界不会在意你的自尊
  8. delphi播放wav声音
  9. usb驱动修复_win10 1903 5月29号的质量更新修复了哪些问题?
  10. OpenWrt开发必备软件模块——进程管理服务procd
  11. Unity Metaverse(六)、关于Avatar换装系统的示例工程
  12. LightOJ 1224 DNA Prefix(字典树)
  13. NOI2021 D类打铁记
  14. cass简码大全_考考你......列出 南方cass 简码指令50个。
  15. 麒麟820 soc鸿蒙系统,麒麟1020 SoC和麒麟820:华为下一代芯片?
  16. Matlab基础知识五
  17. java基础---悲观锁和乐观锁
  18. 短裙高跟丝袜外拍,真的很漂亮哦!
  19. ubuntu下80端口无权限问题
  20. 用户'sa'登录失败(错误18456)解决方案图解----本人备注

热门文章

  1. splitcontainer控件固定Panel的大小
  2. IIS6.0架设网站常见问题
  3. JavaEE项目 Web聊天室(JSP实现)
  4. Flash CS6中文版
  5. 解决jupyter无法自动打开网页
  6. Inno Setup 6.0.0+ 繁体中文语言包
  7. 关于MAC的pkg和mpkg的分别
  8. 模电笔记快速整理之《模拟电子技术基础(第四版)》上海交大网课版 1-2章
  9. 解决maven报错JAVA_HOME should point to a JDK not a JRE问题
  10. DUILIB相对位置修改为锚概念