编写程序实现租车流程并计算租赁价格
以下只给出源码框架,需要查看完整代码的可于微信搜索公众号“钥道不止”或“suoyue_zhan”或下方直接扫码关注并在后台回复“524056”即可获取完整代码
RentMgrSys.java
package com.demo;
import java.util.Scanner;
import com.cars.MotoVehicle; //导入另一个包的文件
public class RentMgrSys {
private static MotoVehicle motor; //汽车
private static double rentCost; //租赁费用
public static MotoVehicle getMotor() {
return motor;
}
public static void setMotor(MotoVehicle motor) {
RentMgrSys.motor = motor;
}
public static double getRentCost() {
return rentCost;
}
public static void setRentCost(double rentCost) {
RentMgrSys.rentCost = rentCost;
}
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
MotoVehicle moto=null; //汽车
System.out.println("***********欢迎光临跑得快汽车租赁公司***********");
System.out.println("1.轿车\t2.客车\t3.卡车");
System.out.print("请选择你要租赁的汽车类型:");
int choose=input.nextInt();
System.out.print("请输入您要租赁的天数:");
int days=input.nextInt();
rentManage(choose, days, 100, 100, 100, 100.0); // vehicleType, brandId, seatCount,ton设置默认为100
moto = RentMgrSys.getMotor(); // 方便测试修改重新取得moto对象
double money = RentMgrSys.getRentCost(); // 方便测试取得租车费用信息money
System.out.println("\n=====================================");
System.out.println("分配给您的汽车牌号是:"+moto.getVehicleId());
System.out.println("您需要支付的租赁费用是:"+money+"元。");
input.close();
}
/**
* 租车管理
* @param type
* @param days
* @param vehicleType
* @param brandId
* @param seatCount
* @param ton
*/
public static void rentManage(int type, int days, int vehicleType, int brandId, int seatCount, double ton) {
}
}
MotoOperation.java
package com.demo;
import com.cars.MotoVehicle;
import com.cars.Bus;
import com.cars.Car;
import com.cars.Truck;
/**
* 汽车业务
*/
public class MotoOperation {
/**
* 租赁汽车
* @param motoType 汽车类型
* @return 汽车
*/
public MotoVehicle motoLeaseOut(String motoType){
return motorRentCommon(motoType, 0, 0, 0, 0);
}
/**
* 租赁汽车
* @param motoType 汽车类型
* @param brandId 品牌
* @param typeId 型号
* @param seatCount 座位数
* @param ton 吨数
* @return 汽车
*/
public MotoVehicle motorRentCommon(String motoType, int brandId, int typeId, int seatCount, double ton){
MotoVehicle moto=null;
return moto; //返回一个汽车对象
}
}
MotoVehicle.java
package com.cars;
/**
*汽车的抽象类
*/
public abstract class MotoVehicle {
private String vehicleId; //车牌号
private String brand; //品牌
private int perRent; //日租金
//定义两个抽象方法
public abstract float calRent(int days); //计算租金
public abstract void leaseOutFlow(); //租车流程
/**
* 构造函数
*/
public MotoVehicle() {
}
public MotoVehicle(String vehicleId,String brand,int perRent) {
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;
}
}
Car.java
package com.cars;
import java.util.Scanner;
/**
* 轿车
*/
public class Car extends MotoVehicle{
private String type; // 型号
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Car() {
}
public Car(String vehicleId, String brand, String type, int perRent) {
super(vehicleId, brand, perRent);
this.type = type;
}
/**
* 重写计算租金
*/
public float calRent(int days) {
return this.getPerRent() * days;
}
/**
* 重写租车流程
*/
public void leaseOutFlow() {
}
public void rentVehicleFlow(int brandId, int typeId) {
}
}
Bus.java
package com.cars;
import java.util.Scanner;
/**
* 客车
*/
public class Bus extends MotoVehicle{
private int seatCount; // 座位数
public int getSeatCount() {
return seatCount;
}
public void setSeatCount(int seatCount) {
this.seatCount = seatCount;
}
public Bus() {
}
public Bus(String vehicleId, String brand, int perRent, int seatCount) {
super(vehicleId, brand, perRent);
this.seatCount = seatCount;
}
/**
* 重写计算租金
*/
public float calRent(int days) {
return this.getPerRent() * days;
}
/**
* 重写租车流程
*/
public void leaseOutFlow() {
}
public void rentBusFlow(int busBrandId, int seatCount) {
}
}
Truck.java
package com.cars;
import java.util.Scanner;
/**
* 卡车
*/
public class Truck extends MotoVehicle{
private double ton; //吨
//设置和取得车辆载重信息即吨的信息
public double getTon() {
return ton;
}
public void setTon(double ton) {
this.ton = ton;
}
// TODO: 重载构造方法,利用构造方法的参数,给成员变量赋值
public Truck() {
}
public Truck(String vehicleId, String brand, double ton, int perRent) {
super(vehicleId, brand, perRent);
this.ton = ton;
}
// TODO: 完成构造方法
/**
* 重写计算租金
*
*/
public float calRent(int days) {
return this.getPerRent() * days * (float)this.getTon();
}
/**
* 重写租车流程
*/
public void leaseOutFlow() {
Scanner input=new Scanner(System.in);
System.out.println("1.解放\t2.东风");
System.out.print("请选择你要租赁的卡车品牌:");
int truckBrandId = input.nextInt(); // TODO 输入品牌:truckBrandId
System.out.print("请输入卡车的吨数:");
ton = input.nextDouble();// TODO 输入吨数
// 为了测试用例使用,调整实现逻辑
rentVehicleFlow(truckBrandId, ton);
input.close();
}
/**
* 重写租车流程
* @param brandId 品牌
* @param ton 吨数
*/
public void rentVehicleFlow(int brandId, double ton) {
//根据品牌:brandId,吨数:ton设置车辆的信息
if (brandId == 1) {
this.setBrand("解放");
this.setTon(ton); // 设置卡车吨数
this.setPerRent(800);
this.setVehicleId("京GD56577"); // 设置车牌号
} else if (brandId == 2) {
this.setBrand("东风");
this.setTon(ton); // 设置卡车吨数
this.setPerRent(700);
this.setVehicleId("京GD53456"); // 设置车牌号
} else
System.out.println("对不起,暂时没有此品牌的客车"); // 客车
}
}