抽象类,接口,多态的收尾的小项目

汽车租赁系统

所有的汽车都具备品牌,车牌号,日租金

大巴车Bus:大巴车有很多的座位

普通轿车Car:有排量

商务车Mpv:空间大

根据不同的车型有不同的日租金的方法和租车的流程

大巴车:日租金1000,押金10万,3天起租

租车流程:5年内没有任何扣分的A驾照

普通轿车:日租金400,押金5万,1天起租

租车流程:1年内没有任何扣分的c驾照

商务车:日租金800,押金8万,2天起租

租车流程:3年内没有扣分的B驾照

要求,应用多态,简单工厂,从键盘录入选择车型

所有的程序步骤都可以看成三步:

1.获取数据

2.处理数据

3.显示处理完的数据

首先写一个IVehicle接口

内容:

public interface IVehicle {public  double calcRent();public  boolean leaseOutFlow();
}

其次,创建Vehicle类:放共有的数据

内容:

public abstract class Vehicle implements IVehicle {private  String  vehicleId;//车牌号private String brand;//车的品牌private int perRent;//日租金private int deposit;//车的押金private int beginDayRent;//起租天数private int daysOfRent;//租车的天数   public Vehicle(){}public Vehicle(String vehicleId, String brand, int perRent, int deposit, int beginDayRent, int daysOfRent) {this.vehicleId = vehicleId;this.brand = brand;this.perRent = perRent;this.deposit = deposit;this.beginDayRent = beginDayRent;this.daysOfRent = daysOfRent;}public String getVehicleId() {return vehicleId;}public void setVehicleId(String vehicleId) {this.vehicleId = vehicleId;}public String getBrand() {return brand;}public void setBrand(String brand) {this.brand = brand;}public int getPerRent() {return perRent;}public void setPerRent(int perRent) {this.perRent = perRent;}public int getDeposit() {return deposit;}public void setDeposit(int deposit) {this.deposit = deposit;}public int getBeginDayRent() {return beginDayRent;}public void setBeginDayRent(int beginDayRent) {this.beginDayRent = beginDayRent;}public int getDaysOfRent() {return daysOfRent;}public void setDaysOfRent(int daysOfRent) {this.daysOfRent = daysOfRent;}/*** 所有的车型都是用此种方式计算资金*/@Overridepublic double calcRent() {double result=0;result=this.perRent*this.daysOfRent;      return result;}@Overridepublic abstract boolean leaseOutFlow();}

做Bus类:

内容:

import java.util.Scanner;public class Bus extends Vehicle {private int seats;public Bus(){}public Bus(String vehicleId,String  brand,int percent,int deposit,int beginDayRent,int daysOfRent,int seats) {super(vehicleId,brand,percent,deposit,beginDayRent,daysOfRent);this.seats = seats;}public int getSeats() {return seats;}public void setSeats(int seats) {this.seats = seats;}@Overridepublic boolean leaseOutFlow() {boolean flag=false;if(this.getDeposit()>=100000 && this.getBeginDayRent()>=3){//说明要调用本地的交通管理局的系统,根据驾照的编号从系统中获取驾照信息Scanner input=new Scanner(System.in);System.out.println("是否是五年内没有扣分的A驾照");String answer=input.next();if("y".equals(answer)){System.out.println("给大巴车的钥匙,车就可以开走了");flag=true;}else{System.out.println("驾照不符合要求");}}else{System.out.println("不符合起租天数");}return flag;}}

做Car类

内容:

import java.util.Scanner;public class Car extends Vehicle {private double displacement;//排量public Car(){}public Car(String vehicleId,String  brand,int percent,int deposit,int beginDayRent,int daysOfRent,double displacement) {super(vehicleId,brand,percent,deposit,beginDayRent,daysOfRent);this.displacement = displacement;}public double getDisplacement() {return displacement;}public void setDisplacement(double displacement) {this.displacement = displacement;}@Overridepublic boolean leaseOutFlow() {boolean flag=false;if(this.getDeposit()>=50000 && this.getBeginDayRent()>=1){//说明要调用本地的交通管理局的系统,根据驾照的编号从系统中获取驾照信息Scanner input=new Scanner(System.in);System.out.println("是否是一年内没有扣分的C驾照");String answer=input.next();if("y".equals(answer)){System.out.println("给小轿车的钥匙,车就可以开走了");flag=true;}else{System.out.println("驾照不符合要求");}}else{System.out.println("不符合起租天数");}return flag;}}

做Mpv类

内容:

import java.util.Scanner;public class Mpv extends Vehicle {private String space;public Mpv(){}public Mpv(String vehicleId,String  brand,int percent,int deposit,int beginDayRent,int daysOfRent,String space) {super(vehicleId,brand,percent,deposit,beginDayRent,daysOfRent);this.space = space;}public String getSpace() {return space;}public void setSpace(String space) {this.space = space;}@Overridepublic boolean leaseOutFlow() {boolean flag=false;if(this.getDeposit()>=80000 && this.getBeginDayRent()>=2){//说明要调用本地的交通管理局的系统,根据驾照的编号从系统中获取驾照信息Scanner input=new Scanner(System.in);System.out.println("是否是三年内没有扣分的B驾照");String answer=input.next();if("y".equals(answer)){System.out.println("给mpv车的钥匙,车就可以开走了");flag=true;}else{System.out.println("驾照不符合要求");}}else{System.out.println("不符合起租天数");}return flag;}}

在做一个简单工厂ManageVehicle类

内容:

/*** 管理交通工具的类* @author tedu**/
public class ManageVehicle {//简单工厂public static Vehicle getVehicle(String type){Vehicle vehicle=null;if("car".equals(type)){vehicle=new Car("京A123456","奔驰",400,50000,1,2,2.0);}else if("bus".equals(type)){vehicle=new Bus("京A654321","黄海",1000,100000,3,2,50);}else if("mpv".equals(type)){vehicle=new Mpv("京N123456","GMC",800,80000,2,2,"大");}return vehicle;}//计算租金public static double calcRent(IVehicle iv){return iv.calcRent();}//租车流程public static  boolean leaseOutFlow(IVehicle iv){return iv.leaseOutFlow();}
}

最后做一个含有main()的类

内容:

import java.util.Scanner;public class Demo1 {public static void main(String[] args) {Scanner input=new  Scanner(System.in);System.out.println("*************欢迎光临XXX汽车租赁系统*******************");System.out.println("1.轿车\t2.大巴车\t3商务车");System.out.println("请输入租车的类型");int choice=input.nextInt();String type=null;if(choice==1){type="car";}else if(choice==2){type="bus";}else if(choice==3){type="mpv";}else{type="car";}//根据类型生产车辆Vehicle vehicle=ManageVehicle.getVehicle(type);boolean flag=ManageVehicle.leaseOutFlow(vehicle);if(flag){//符合租车的条件,可以租车,租完后要计算租金System.out.println("请输入租车的天数");int days=input.nextInt();vehicle.setDaysOfRent(days);double money=ManageVehicle.calcRent(vehicle);System.out.println("需要付款:"+money);         }}}

汽车租赁小项目(java)相关推荐

  1. 微信小程序汽车租赁小程序

    随着信息技术和网络技术的飞速发展,人类已进入全新信息化时代,传统管理技术已无法高效,便捷地管理信息.为了迎合时代需求,优化管理效率,各种各样的管理系统应运而生,各行各业相继进入信息管理时代,汽车租赁小 ...

  2. 汽车租赁系统(Java)

    汽车租赁系统采用Java语言编写 ----------------------------------------------------------------该代码亲试有效,欢迎各位dalao对代 ...

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

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

  4. [附源码]SSM计算机毕业设计汽车租赁管理系统论文JAVA

    项目运行 环境配置: Jdk1.8 + Tomcat7.0 + Mysql + HBuilderX(Webstorm也行)+ Eclispe(IntelliJ IDEA,Eclispe,MyEclis ...

  5. [面向对象程序设计] 汽车租赁系统(Java实现)

    通过Java简单实现汽车租赁系统. 1)系统分为管理员和用户角色登录,不同的角色有不同的权限操作: 2)管理员功能:查看.添加.修改和删除车辆信息,查看营业额: 3)用户功能:登录后,可以查看车辆.租 ...

  6. 基于android的汽车租赁平台项目需求分析心得

    背景和目标 当下,汽车行业的发展给人们带来了巨大的便捷,人们出行对车辆的需求也大大增加,由此兴起的汽车租赁服务行业也带给人们巨大便利,人们对租赁服务的大量需求,也使得汽车租赁行业有广阔前景.随着计算机 ...

  7. 汽车租赁小程序来了,汽车租赁小程序开发方案

    随着物联网技术的提升,共享经济在生活.医疗.短租等领域多点开花,共享雨伞.共享充电宝.共享洗衣机等共享经济产物被广泛应用到生活中,赋能传统行业的发展,带来了心得经济增长点,更好的促进了资源配置,服务了 ...

  8. php汽车租赁网站_ThinkPHP实战开发汽车租赁网站项目教程

    童老师thinkphp实战开发网站项目的第三季度,与第二季度相比,难度有了明显的提高不仅涉及到了RBAC权限控制功能,更是增加了手机端的功能,还有更多功能知识点就不一一列举,希望学员们能够自己在课程中 ...

  9. 坦克大战项目java_新手小项目-java坦克大战

    我们需要知道窗口显示了哪些东西.百度搜索这个小游戏,或者上小游戏网站玩几次就可以知道游戏规则了http://www.7k7k.com/swf/129505.htm 我们可以看到游戏界面和游戏玩法 先画 ...

最新文章

  1. Mac 从Makefile 编译 Rocksdb 源码的一些注意事项
  2. Python 函数知识汇总
  3. python3.7.1使用_在不影响使用python3.7.1的功能的情况下,是否可以从python代码中删除所有的ufuture_uu语句?...
  4. 恢复出厂设置android手机号码,安卓手机怎么恢复出厂设置
  5. C语言文件指针的基本函数介绍包含了fpoen、fclose、fgetc、fputc、fscanf、fprintf、fgets、fputs、fread、fwrite函数以及文件定位函数.
  6. SpringCloud+Redis
  7. java -为什么重写equals(),还需要重写hashCode()?
  8. (C语言)2066 分组统计
  9. CGCS2000大地坐标系、北斗坐标系(BDCS)与WGS84坐标系的差异
  10. Creo参数曲面设计视频教程
  11. YDUI Touch InfiniteScroll无限加载数据测试
  12. 积沙成塔之VC不规则按钮的创建
  13. 我的2011--虚荣、挣扎、总结和转变的一年
  14. python写用用户名密码程序_python写用’户登录程序‘的过程
  15. 学会做笔记-子弹笔记学习概要三
  16. 数字化转型,要把功夫炼到任督二脉
  17. tortoiseGit管理的文件没有绿色红色等图标
  18. 蓝牙地址解析(NAP/UAP/LAP)
  19. AppCompat V21:将 Materia Design 兼容到5.0之前的设备
  20. 使用Navicat 连接oracle “ORA-03135: Connection Lost Contact”

热门文章

  1. 上传Excel文件进度条原理
  2. 【FL论文阅读】Communication-Efficient Learning of Deep Networks from Decentralized Data
  3. 180-爬虫3-自动操作浏览器工具selenium模块的使用
  4. Activiti工作流会签与获取下一节点任务信息
  5. c语言--余数正负判断,printf函数占位符
  6. --nuhub--linux
  7. JavaScript事件驱动模型
  8. android控件显示在最上层,「总是可见的时钟和备忘录」永远显示在屏幕最上层的贴心助手(Android)...
  9. K3实现按虚拟件/组件发料
  10. 【Android归纳】基于XListView的下拉刷新、上拉加载更多的控件分析