汽车租赁系统
汽车租赁系统
设计步骤
1.设计需求
2.面向对象的设计思想
(1)名词【类,类的属性】
(2)动词【类的方法】
优化设计
设计组成
1.汽车类(父类)
(1)品牌,
(2)日租金
(3)车牌号
(4)构造方法
(5)计算租金
2.轿车类(子类)
(1)品牌,
(2)日租金
(3)车牌号
(4)型号【特有】
(5)构造方法
(5)重写轿车租金计算方法
3.客车类(子类)
(1)品牌,
(2)日租金
(3)车牌号
(4)座位数【特有】
(5)构造方法
(5)重写客车租金计算方法
4.汽车服务类
(1)初始化汽车信息
(2)根据给出的信息查找车辆
5.租赁管理类
(1)购置汽车
(2)客户租车给定的条件
(3)收集客人信息找出车
(4)租车&计算租金
例:
1、父类--------------------------------------------------------------------------------------------------------------------------------------------------
package com.cn.vehicle;
public abstract class Motoqiche {
private String pingPai; //品牌
private String motoID; //车牌
private int perRent; //日租金
//构造方法
public Motoqiche() {}
public Motoqiche(String pingPai,String motoID,int perRent) {
this.pingPai=pingPai;
this.motoID=motoID;
this.perRent=perRent;
}
public String getPingPai() {
return pingPai;
}
public void setPingPai(String pingPai) {
this.pingPai = pingPai;
}
public String getMotoID() {
return motoID;
}
public void setMotoID(String motoID) {
this.motoID = motoID;
}
public int getPerRent() {
return perRent;
}
public void setPerRent(int perRent) {
this.perRent = perRent;
}
//计算租金的抽象方法
public abstract double renMoney(int day);
}
2.子类轿车-----------------------------------------------------------------------------------------
package com.cn.vehicle;
//轿车类
public class Cat extends Motoqiche {
private String type; //轿车特有的型号
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
//构造方法
public Cat() {}
public Cat(String pingPai,String motoID,int perRent,String type) {
super(pingPai,motoID,perRent); //继承父类的品牌,车牌号,日租金
this.type = type;
}
@Override
public double renMoney(int day) {
double dayRent=this.getPerRent()*day;
if(day>7&&day<=30) {
dayRent*=0.9;
}else if(day>30&&day<=150) {
dayRent*=0.8;
}else {
dayRent*=0.7;
}
return dayRent;
}
}
3.子类客车---------------------------------------------------------------------------------------------------------------
package com.cn.vehicle;
//客车类
public class Bus extends Motoqiche {
private int zuiWei; //客车特有座位数
public int getZuiWei() {
return zuiWei;
}
public void setZuiWei(int zuiWei) {
this.zuiWei = zuiWei;
}
//构造方法
public Bus() {}
public Bus(String pingPai,String motoID,int perRent,int zuiWei) {
super(pingPai,motoID,perRent);
this.zuiWei = zuiWei;
}
@Override
public double renMoney(int day) {
double dayRent=this.getPerRent()*day;
if(day>=3&&day<7) {
dayRent*=0.9;
}else if(day>=7&&day<30) {
dayRent*=0.8;
}else if(day>=30&&day<150){
dayRent*=0.7;
}else {
dayRent*=0.6;
}
return dayRent;
}
}
4.服务类--------------------------------------------------------------------------------------------------------------
package com.cn.vehicle.text;
import com.cn.vehicle.Bus;
import com.cn.vehicle.Cat;
import com.cn.vehicle.Motoqiche;
//租车服务类
public class Motofuwu {
//将初始化信息存放数组中
public Motoqiche[] motos=new Motoqiche[8];
//初始化车辆信息
public void init() {
motos[0]=new Cat("宝马","晋A12345",800,"X6");
motos[1]=new Cat("宝马","晋A33345",600,"550i");
motos[2]=new Cat("别克","晋A12445",300,"林荫大道");
motos[3]=new Cat("别克","晋A09875",600,"GL8");
motos[4]=new Bus("金杯","晋A13445",800,16);
motos[5]=new Bus("金杯","晋A12665",1500,32);
motos[6]=new Bus("金龙","晋A12555",800,16);
motos[7]=new Bus("金龙","晋A12390",1500,32);
}
//根据给出的信息寻找车辆
public Motoqiche xunzhao(String pingPai,String type,int zuoWei) {
Motoqiche moto=null;
for(Motoqiche mymoto:motos) {
if(mymoto instanceof Cat) {
Cat cat=(Cat)mymoto;
//寻找的为轿车
if(cat.getPingPai().equals(pingPai)&&cat.getType().equals(type)) {
moto=cat;
break;
}
}else if(mymoto instanceof Bus) {
Bus bus=(Bus)mymoto;
//寻找客车
if(bus.getPingPai().equals(pingPai)&&bus.getZuiWei()==(zuoWei)) {
moto=bus;
break;
}
}
}
return moto;
}
}
5.测试类--------------------------------------------------------------------------------------------------------
package com.cn.vehicle.text;
import java.util.Scanner;
import com.cn.vehicle.Motoqiche;
public class MotoRentText {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
Motofuwu rentFuwu=new Motofuwu();
//购置汽车
rentFuwu.init();
//定义用户需要输入的信息
String pingPai=" ";
String type=" ";
int zuoWei=0;
//收集客人信息
System.out.println("------------------------欢迎光临--------------------------");
System.out.println("请输入您要租赁的汽车类型 1.轿车 2.客车");
int choos1=input.nextInt();
if(choos1==1) {
//租赁轿车
System.out.println("请输入您要租赁的轿车品牌 1.宝马 2.别克");
int no=input.nextInt();
if(no==1) {
pingPai="宝马";
System.out.println("请输入您要租赁的宝马车型 1.X6 2.550i");
int n=input.nextInt();
type=(n==1)?"X6":"550i";
}else {
pingPai="别克";
System.out.println("请输入您要租赁的别克车型 1.林荫大道 2.GL8");
int n=input.nextInt();
type=(n==1)?"林荫大道":"GL8";
}
}else if(choos1==2) {
//租赁客车
System.out.println("请输入您要租赁的轿车品牌 1.金杯 2.金龙");
int no=input.nextInt();
if(no==1) {
pingPai="金杯";
System.out.println("请输入您要租赁的金杯座位数 1.16 2.32");
int n=input.nextInt();
zuoWei=(n==1)?16:32;
}else {
pingPai="金龙";
System.out.println("请输入您要租赁的金龙座位数 1.16 2.32");
int n=input.nextInt();
zuoWei=(n==1)?16:32;
}
}
//租车&计算金额
Motoqiche moto=rentFuwu.xunzhao(pingPai, type, zuoWei);
System.out.println("租车成功,请按如下车牌提车"+moto.getMotoID());
System.out.println("请输入您租赁的天数");
int day=input.nextInt();
double summoney=moto.renMoney(day);
System.out.println("需要支付"+summoney+"元");
}
}