Java代码~~汽车租赁系统
租车信息:

输出结果:


代码:
1、先定义抽象类(汽车类:Moto)
package cn.aura.demo01;
public abstract class Moto {
//公共属性
private String id;//车牌号
private String brand;//品牌
private int preRent;//日租金
//构造方法
public Moto(String id, String brand, int preRent) {
this.id = id;
this.brand = brand;
this.preRent = preRent;
}
//set和get方法
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 getPreRent() {
return preRent;
}
public void setPreRent(int preRent) {
this.preRent = preRent;
}
//计算租金方法
public abstract double calRent(int days);
}
2.定义轿车类继承汽车类
package cn.aura.demo01;
/**
* 轿车类
*/
public class Car extends Moto{
//私有属性
private String type;//型号
//set和get方法
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
//构造方法
public Car(String id, String brand, String type,int preRent) {
super(id, brand, preRent);
this.type = type;
} //重写计算租金的算法
@Override
public double calRent(int days) {
if(days >0 && days <= 7) {
//days小于7天,不打折
return getPreRent()*days;
}else if (days > 7 && days <= 30) {
//days大于7天,9折
return getPreRent()*days*0.9;
}else if (days > 30 && days <= 150) {
//days大于30天,8折
return getPreRent()*days*0.8;
}else if (days > 150) {
//days大于150天,7折
return getPreRent()*days*0.7;
}
return 0;
}
}
3.定义客车类
package cn.aura.demo01;
/**
* 客车类
*/
public class Bus extends Moto{
//私有属性
private int seatCount;//座位数
//set和get方法
public int getSeatCount() {
return seatCount;
}
public void setSeatCount(int seatCount) {
this.seatCount = seatCount;
}
//构造方法
public Bus(String id, String brand, int seatCount, int preRent) {
super(id, brand, preRent);
this.seatCount = seatCount;
}
//重写计算租金的算法
@Override
public double calRent(int days) {
if(days >0 && days <3) {
//days小于3天,不打折
return getPreRent()*days;
}else if (days >= 3 && days < 7) {
//days大于3天,9折
return getPreRent()*days*0.9;
}else if (days >= 7 && days <30) {
//days大于3天,8折
return getPreRent()*days*0.8;
}else if (days >= 30 && days <150) {
//days大于30天,7折
return getPreRent()*days*0.7;
}else if (days >= 150) {
//days大于150天,6折
return getPreRent()*days*0.6;
}
return 0;
}
}
4.定义汽车业务类
package cn.aura.demo01;
/**
* 定义汽车业务类
*/
public class MotoOperation {
//初始化数组
public static Moto[] motos = new Moto[8];
//创建8个汽车对象
public void init() {
motos[0] = new Car("京NY28558", "宝马", "X6", 800);
motos[1] = new Car("京CNY3284", "宝马", "550i", 600);
motos[2] = new Car("京NT37465", "别克", "林荫大道", 300);
motos[3] = new Car("京NT96968", "别克", "GL8", 600);
motos[4] = new Bus("京6566754", "金杯", 16, 800);
motos[5] = new Bus("京8696997", "金龙", 16, 800);
motos[6] = new Bus("京9696996", "金杯", 34, 1500);
motos[7] = new Bus("京8696998", "金龙", 34, 1500);
}
//租赁汽车的方法
public Moto motoLeaseOut(String brand,String type,int seat) {
//for循环遍历数组motos
for(int i=0;i<motos.length;i++){
if (brand.equals(motos[i].getBrand())) {
// 判断Moto类的motos[i]的类型是否和Car一样
if (motos[i] instanceof Car) {
// 强转成小汽车Car
Car car = (Car) motos[i];
if (type.equals(car.getType())) {
return car;
}
}
if(motos[i] instanceof Bus){
// 强转成大客车Bus
Bus bus = (Bus) motos[i];
if (seat == bus.getSeatCount()) {
return bus;
}
}
} }
//如果没有就返回空
return null;
}
}
5.定义测试类
package cn.aura.demo01; import java.util.Scanner; /**
* 汽车租赁管理类
*/
public class TestRent {
//主函数
public static void main(String[] args) {
MotoOperation motoOperation = new MotoOperation();
// 初始化汽车
motoOperation.init();
//设置一个空容器
Moto moto = null;
// 提示信息
System.out.println("***********欢迎光临腾飞汽车租赁公司***********");
System.out.println("1、轿车 2、客车");
System.out.println("请输入你要租赁的汽车类型:");
// 获取用户输入
Scanner scanner = new Scanner(System.in);
int flag = scanner.nextInt();
if (flag == 1) {
//轿车
System.out.println("请选择你要租赁的汽车品牌:1、别克 2、宝马");
int brand = scanner.nextInt();
if (brand == 1) {
System.out.println("请选择你要租赁的汽车类型:1、林荫大道 2、GL8");
int type = scanner.nextInt();
if (type == 1) {
moto = motoOperation.motoLeaseOut("别克", "林荫大道", 4);
} else if (type == 2) {
moto = motoOperation.motoLeaseOut("别克", "GL8", 4);
}
} else if (brand == 2) {
System.out.println("请选择你要租赁的汽车类型:1、X6 2、550i");
int type = scanner.nextInt();
if (type == 1) {
moto = motoOperation.motoLeaseOut("宝马", "X6", 4);
} else if (type == 2) {
moto = motoOperation.motoLeaseOut("别克", "550i", 4);
}
}
} else if (flag == 2) {
//客车
System.out.println("请选择你要租赁的汽车品牌:1、金龙 2、金杯");
int brand = scanner.nextInt();
if (brand == 1) {
System.out.println("请选择你要租赁的汽车座位数:1、16座 2、34座");
int type = scanner.nextInt();
if (type == 1) {
moto = motoOperation.motoLeaseOut("金龙", "", 16);
} else if (type == 2) {
moto = motoOperation.motoLeaseOut("金龙", "", 34);
}
} else if (brand == 2) {
System.out.println("请选择你要租赁的汽车座位数:1、16座 2、34座");
int type = scanner.nextInt();
if (type == 1) {
moto = motoOperation.motoLeaseOut("金杯", "", 16);
} else if (type == 2) {
moto = motoOperation.motoLeaseOut("金杯", "", 34);
}
}
}
//客户汽车匹配完成
if (moto != null) {
// 获取用户租车天数
System.out.println("请输入您的租车天数:");
int days = scanner.nextInt();
// 计算租车钱
double money = moto.calRent(days);
System.out.println("分配给您的汽车牌号是:" + moto.getId());
System.out.println("您需要支付的租赁费用是:" + money + "元");
}else {
System.out.println("很抱歉先生:当前的公司内,暂无您要的汽车类型!请重新选择!");
} } }
Java代码~~汽车租赁系统的更多相关文章
- Java汽车租赁系统[源码+数据库]
系统名称 Java汽车租赁系统 (源码在文末) 系统概要 汽车租赁系统总共分为两个大的模块,分别是系统模块和业务模块.其中系统模块和业务模块底下又有其子模块. 功能模块 一.业务模块 1.客户管理 ...
- 一种基于Java Swing/HTML/MySQL的汽车租赁系统
该项目是一个Java的课程作业(大二),主要运用Java.Swing.HTML.MySQL,实现基本的租车逻辑.界面可视化.信息导出.数据存储等功能.实现管理员.用户两种角色登录,并结合Java开发中 ...
- 深入.NET和C#的小型汽车租赁系统的框架
前言:写这个小型系统之前呢,我们应该要猜测可能要用到哪些知识点. 那么对于这个小型系统:主要用到了如下的知识: 封装,集合(ArrayList和HashTable)和泛型和非泛型集合(泛型:List ...
- C#汽车租赁系统 完整版
Truck.cs类 //卡车类 public class Truck : Vehicle1 { //重载 public int Load { get; set; } //构造函数 public T ...
- C#汽车租赁系统
类图: 父类(车类,抽象类) /// <summary> /// 车辆基本信息类.搞一个抽象类玩玩 /// </summary> public abstract class V ...
- Springboot+vue 实现汽车租赁系统(毕业设计二)(前后端项目分离)
文章目录 1.系统功能列表 2.管理员端界面 2.1 商家登录界面 2.2 用户信息管理界面 2.3 汽车管理界面 2.4 订单界面 2.5 汽车图形报表 2.6 优惠券新增界面 3.普通用户界面 3 ...
- .Net中的AOP系列之构建一个汽车租赁应用
返回<.Net中的AOP>系列学习总目录 本篇目录 开始一个新项目 没有AOP的生活 变更的代价 使用AOP重构 本系列的源码本人已托管于Coding上:点击查看. 本系列的实验环境:VS ...
- 《Java从入门到放弃》JavaSE篇:综合练习——单身狗租赁系统(数组版)
因为现在只学习了基本语法,所以在综合练习之前,先补充关于方法概念. 方法的作用:把一系列的代码放在一起,然后再取个别名.之后通过这个别名的调用,就相当于执行了这一系列的代码. 方法的语法:([]中的内 ...
- 《Java从入门到放弃》JavaSE入门篇:练习——单身狗租赁系统
今天,我们要玩个大的!!! 我们把之前使用数组做的这个单身狗系统改版成数据库版本,并且使用面向对象里面的一些简单思想.如果有不知道这个系统的看官,请跳转到目录页,然后再选择单身狗系统(数组版)先围观五 ...
随机推荐
- 使用OpenCV和imagezmq通过网络实时传输视频流 | live video streaming over network with opencv and imagezmq
本文首发于个人博客https://kezunlin.me/post/b8847d9f/,欢迎阅读最新内容! live video streaming over network with opencv ...
- IPv6,无需操作就可升级?
最近这段时间,5G 出现在你能看到的各种信息里,铺天盖地的宣传提醒着大家新一代互联网的到来.其实早在几年前 5G 就有所提及,可是为什么到现在才开始窜上热门呢?这就涉及到了 IPv6. 或许有不少朋友 ...
- goroutiine同步/channel、互斥锁、读写锁、死锁/条件变量
1. Goroutine同步[数据同步] 为什么需要goroutine同步 gorotine同步概念.以及同步的几种方式 1.1 为什么需要goroutine同步 package main impor ...
- 【前端】 在前端利用数学函数知识+box-shadow解波浪图形
序 今天正在刷数学函数相关题目,刷到了下面这篇文章,哇哦-有意思. 利用cos和sin实现复杂的曲线.传送门在下面. CSS 技巧一则 -- 在 CSS 中使用三角函数绘制曲线图形及展示动画 正巧在复 ...
- 在.NET Core中使用Jwt对API进行认证
在.NET Core中想用给API进行安全认证,最简单的无非就是Jwt,悠然记得一年前写的Jwt Demo,现在拿回来改成.NET Core的,但是在编码上的改变并不大,因为Jwt已经足够强大了.在项 ...
- Mybatis一级缓存和二级缓存总结
1:mybatis一级缓存:级别是session级别的,如果是同一个线程,同一个session,同一个查询条件,则只会查询数据库一次 2:mybatis二级缓存:级别是sessionfactory级别 ...
- Qt的安装
由于之前用的vs2017是集成c++环境的,加之dev c++ 编码管理起来不是很方便,Mytc (win10不支持) ,所以转而向Qt 开发工具,以下是大概安装过程 下载地址 清华源:https:/ ...
- Authentication 接口验证访问 (C#)
private HttpClient _httpClient = new HttpClient(); private string PostToOwner(CarOwnerCoupon postDat ...
- java8 按两个属性分组,并返回扁平List; stream排序
--------------- java8 按两个属性分组,并返回扁平List /** * 设置大区小区分组排序 * @param dtoList */ private List<Perform ...
- 点击按钮每次都能实现图片的旋转和切换(swift)
效果如图: 代码如下: // // ViewController.swift // TwoSidedView // // Created by mayl on 2017/12/14. // Copyr ...