汽车租聘系统(面向对象)
package Car_mgr;
import Car_Rental.Bus;
import Car_Rental.Car;
import Car_Rental.MotoVehicle;
//汽车业务类
public class MotoOperation{
//汽车类型的数组,将该数组声明为父类类型
public MotoVehicle[] motos = new MotoVehicle[8];
// 初始化汽车信息
public void init() {
motos[0] = new Car("京N78888","宝马",880,"X6"); //MotoVehicle m = new Car();
motos[1] = new Car("京S7986","宝马",680,"550i"); //MotoVehicle m = new Car();
motos[2] = new Car("京A3434","别克",300,"林荫大道"); //MotoVehicle m = new Car();
motos[3] = new Car("京W5666","别克",600,"GLB"); //MotoVehicle m = new Car();
motos[4] = new Bus("京I3333","金杯",880,16); //MotoVehicle m = new Bus();
motos[5] = new Bus("京I2121","金杯",1500,34); //MotoVehicle m = new Bus();
motos[6] = new Bus("京F6654","金龙",880,16); //MotoVehicle m = new Bus();
motos[7] = new Bus("京B9878","金龙",1500,34); //MotoVehicle m = new Bus();
}
//租车:根据用户提供的条件去汽车数组中查找相应车辆并返回
// 如果租赁的是客车 需要的条件:品牌 座位数 型号null
//如果租赁的是轿车 需要的条件:品牌 型号 座位数0
public MotoVehicle motoLesseOut(String brand,String type,int seat) {
MotoVehicle moto = null;
for(MotoVehicle mymoto : motos) {
if(mymoto instanceof Car) {
Car car = (Car)mymoto;
if(car.getBrand().equals(brand) && car.getType().equals(type)) {
moto = car;
break;
}
}else {
Bus bus = (Bus)mymoto;
if(bus.getBrand().equals(brand) && bus.getSeatCount()==seat) {
moto = bus;
break;
}
}
}
return moto;
}
package Car_mgr;
import java.util.Scanner;
import Car_Rental.MotoVehicle;
//汽车租赁管理类:测试类
public class RentMgr {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
MotoOperation motoMgr = new MotoOperation();
//租赁公司首先需要购置汽车
motoMgr.init();
System.out.println("*******欢迎光临租赁公司******");
System.out.println("1,轿车\n2,客车");
System.out.print("请选择您要租赁的汽车类型:");
int motoType = input.nextInt();
String brand = " ";//品牌
String type = " ";//型号
int seat = 0;//座位数
if(motoType == 1) {
//租赁轿车
System.out.println("请选择您要租赁的轿车品牌:1,别克 2,宝马");
int choose = input.nextInt();
if(choose == 1) {
brand = "别克";
System.out.println("请选择您要租赁的汽车型号:1,林荫大道 2.GLB");
type = (input.nextInt() == 1)?"林荫大道":"GLB";
}else if(choose == 2) {
brand = "宝马";
System.out.println("请选择您要租赁的汽车型号:1,X6 2.550i");
type = (input.nextInt() == 1)?"X6":"550i";
}
}else if(motoType == 2) {
//租赁客车
type = "";
System.out.println("请选择您要租赁的客车品牌:1,金杯 2,金龙");
brand = (input.nextInt() == 1)?"金杯":"金龙";
System.out.println("请你选择租赁客车的座位数:1,16 2,34");
seat = (input.nextInt() == 1)?16:34;
}
//租车
MotoVehicle moto = motoMgr.motoLesseOut(brand, type, seat);
System.out.print("请输入您的租赁天数:");
int days = input.nextInt();
float money=moto.calcRent(days);
System.out.println("租车成功,请按照如下车牌号去提车:"+moto.getVehicleId());
System.out.println("您需要支付:"+money+"元");
}
}
package Car_Rental;
//客车类
public class Bus extends MotoVehicle{
//座位数
private int seatCount;
public Bus() {
super();
}
public Bus(String vehicleId, String brand, int perRent,int seatCount) {
super(vehicleId,brand,perRent);
this.seatCount = seatCount;
}
public int getSeatCount() {
return seatCount;
}
public void setSeatCount(int seatCount) {
this.seatCount = seatCount;
}
//重写父类的计算租金方法,根据自己的计算租金规则
public float calcRent(int days) {
float price = this.getPerRent()*days;
if(days>=3 && days<7) {
price *=0.9f; //0.9f 是float型,0.9默认是double型
}else if(days>=7 && days<30){
price *= 0.8f;
}else if(days>=30 && days<150) {
price *=0.7f;
}else if(days>=150) {
price *=0.6f;
}
return price;
}
package Car_Rental;
//轿车类
public class Car extends MotoVehicle{
//型号
private String type;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Car() {
super();
}
public Car(String vehicleId, String brand, int perRent,String type) {
super(vehicleId,brand,perRent);
this.type = type;
}
//重写父类的计算租金方法,根据自己的计算租金规则
public float calcRent(int days) {
float price = this.getPerRent()*days;
if(days>7 && days<=30) {
price *=0.9f; //0.9f 是float型,0.9默认是double型
}else if(days>30 && days<=150){
price *= 0.8f;
}else if(days>150) {
price *=0.7f;
}
return price;
}
package Car_Rental;
//汽车类
public abstract class MotoVehicle {
//车牌号 品牌 日租金
private String vehicleId;
private String brand;
private int perRent;
public MotoVehicle() {
super();
}
public MotoVehicle(String vehicleId, String brand, int perRent) {
super();
this.vehicleId = vehicleId;
this.brand = brand;
this.perRent = perRent;
}
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 abstract float calcRent(int days);
汽车租聘系统(面向对象)相关推荐
- C#总结项目《汽车租聘系统》项目代码实例【全注释版】
所有代码均为自己编写,未尽允许,请勿转载 因为所有代码都有比较完整的注释,就不再多写文字了 汽车租聘系统页面样子,程序未加载的截图 关系图 1.Vehicle车辆信息类(车辆信息) //车辆类publ ...
- Java毕设项目-汽车租聘管理系统
题目:汽车租聘管理系统-基于JavaWeb汽车租聘管理系统的设计与实现 1.系统总体设计 1.1开发环境 操作系统:Windows10: 编程语言:Java: 运行环境:Jdk1.7,Jre: 开发工 ...
- 答答租车系统(面向对象综合练习)_JAVA
Description 各位面向对象的小伙伴们,在学习了面向对象的核心概念--类的封装.继承.多态之后,答答租车系统开始营运了. 请你充分利用面向对象思想,为公司解决智能租车问题,根据客户选定的车型和 ...
- java中面向对象租车问题_答答租车系统-Java面向对象的学习
定义 2 个接口 载人接口 IMannedCar.java public interface IMannedCar { int mannedNumber(); } 载货接口 ICarryFreight ...
- 7-1 sdut-oop-7 答答租车系统(类的继承与多态 面向对象综合练习) (30 分)
7-1 sdut-oop-7 答答租车系统(类的继承与多态 面向对象综合练习) (30 分) 各位面向对象的小伙伴们,在学习了面向对象的核心概念--类的封装.继承.多态之后,答答租车系统开始营运了. ...
- java面向对象的小项目_java第二季面向对象结课小项目之答答租车系统
这个小项目是学完java面相对象的练习小项目,还有很多知识点没有用上,是因为并没有完全吸收所学的知识.粗略的完成了这个小项目希望大家指点! 创建Car父类 package com.car; publi ...
- 汽车租赁系统测试java,Java测试-----达达租车系统
测试类 package coom.car_rental.java; import java.util.Scanner; /* * 这是测试主类 */ public class CarRental im ...
- Java面向对象小项目 慕课网Java入门第二季答答租车系统
一.项目背景 编写一个控制台程序,要求实现如下功能: 1.展示所有可租车辆 2.选择车型,租车量 3.显示租车清单,包括:总载货量,总载客量,总金额等: 二.车的类别 客车:只能载客 货车:只能载货 ...
- java简单租车系统 慕课手记_java小项目,租车系统
这学期要学java,本以为暑假学windows程序设计的,没想到一些事情耽误了 ,只能回来再补了,因为学过c++,面向对象的三大特性什么的,c++比java难一点,所以学java感觉还比骄轻松,下面就 ...
最新文章
- FTP 服务搭建及常用的命令脚本及传输协议基础普及
- Linux下l2tp客户端xl2tpd的安装配置
- 从2017年顶会论文看Attention Model - PaperWeekly 第50期
- RPC框架的可靠性设计
- 20170822L08-04老男孩linux实战运维培训-Lamp系列之-Apache服务生产实战应用指南01
- 【二分】Distinct
- 使用Chrome开发者工具调试Android端内网页(微信,QQ,UC,App内嵌页等)
- Jupyter notebook 导入和卸载 conda 虚拟环境
- ci php view,CI映射(加载)数据到view层的方法,ciview_PHP教程
- 百万级访问量网站的技术准备工作
- 当BTC大空头遇上PlusToken,投资竟然成为一门玄学?
- python发邮件被认定为垃圾邮件_【Python】垃圾邮件识别
- 华为手机 标题栏 Notification 8.0 不显示
- 蚂蚁森林中能量自动收取
- 简约生活的72条观念
- Exception in Thread: ValueError: signal number 32 out of range
- LApacheMP基础环境搭建
- MATLAB批量读取航摄相片EXIF信息和GNSS信息以及MATLAB批量经纬度坐标转换空间直角坐标
- 最佳页面置换算法详解
- 同步电复律英文_同步电复律操作规程