用集合和多线程完出租多种善某汽车租赁公司轿车和客车的汽车租赁系统,使得系统可以增加、删除、修改、查看和保存出租车辆信息、租金及折扣,可以多个业务员同时使用操作。
package 开发练习;
import java.util.*;
abstract class MotoVehicle {
//车牌号 品牌 日租金
private String vehicleID;
private String brand;
private int perRent;
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;
}
public abstract float clacRent(int days);
}
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 clacRent(int days){
float price = this.getPerRent()*days;
if(days>=3 && days<7){
price*=0.9f;
}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;
}
}
//轿车类
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, int perRent,String type) {
super(vehicleID, brand,perRent);
this.type = type;
}
public float clacRent(int days){
float price = this.getPerRent()*days;
if(days>7 && days<=30){
price*=0.9f;
}else if(days>30 && days<=150){
price*=0.8f;
}else if(days>150){
price*=0.7f;
}
return price;
}
}
//汽车业务类
class MotoOperation {
public MotoVehicle[] motos = new MotoVehicle[8];
public void init(){
motos[0] = new Car("京NY78654","宝马",800,"X6");
motos[1] = new Car("京NY56457","宝马",600,"550i");
motos[2] = new Car("京NY78454","别克",300,"林荫大道");
motos[3] = new Car("京NT75554","别克",800,"GL8");
motos[4] = new Bus("京NI88899","金杯",800,16);
motos[5] = new Bus("京NL45678","金龙",800,16);
motos[6] = new Bus("京NY78644","金杯",1500,34);
motos[7] = new Bus("京NY78454","金龙",1500,34);
}
public MotoVehicle motoLeaseOut(String brand,String type,int seat){
MotoVehicle moto = null;
for(MotoVehicle mymoto : motos){
if(mymoto instanceof Car){
Car car = (Car)mymoto;
if(car.getBrand().contentEquals(brand) && car.getType().equals(type)){
moto = car;
break;
}
}else{
Bus bus = (Bus)mymoto;
if(bus.getBrand().contentEquals(brand) && bus.getSeatCount()==seat){
moto = bus;
break;
}
}
}
return moto;
}
}
public class RentMgrSys {
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 轿车\t2 客车");
System.out.println("请选择您要租赁的汽车类型");
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.GL8");
type = (input.nextInt() == 1)?"林荫大道":"Gl8";
}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.motoLeaseOut(brand, type, seat);
System.out.println("请输入您的租赁天数:");
int days = input.nextInt();
float money = moto.clacRent(days);
System.out.println("租车成功,请按照如下车牌号去提车:"+moto.getVehicleID());
System.out.println("您需要支付:"+money+"元");
}
}
你好,我是有问必答小助手,非常抱歉,本次您提出的有问必答问题,技术专家团超时未为您做出解答
本次提问扣除的有问必答次数,将会以问答VIP体验卡(1次有问必答机会、商城购买实体图书享受95折优惠)的形式为您补发到账户。
因为有问必答VIP体验卡有效期仅有1天,您在需要使用的时候【私信】联系我,我会为您补发。