public abstract class MotoVehicle {
private String numberPlate;
private double dailyRent;
public String getVehicleId;
public MotoVehicle(String numberPlate, String brand, double dailyRent) {
this.numberPlate = numberPlate;
this.dailyRent = dailyRent;
public String getNumberPlate() {
public void setNumberPlate(String numberPlate) {
this.numberPlate = numberPlate;
public String getBrand() {
public void setBrand(String brand) {
public double getDailyRent() {
public void setDailyRent(double dailyRent) {
this.dailyRent = dailyRent;
public abstract double calRent(int days);
public class MotoOperation {
public MotoVehicle motos[] = new MotoVehicle[8];
motos[0] = new Car("京NY28588", "宝马", 800, "X6");
motos[1] = new Car("京CNY3284", "宝马", 600, "550i");
motos[2] = new Car("京NT37465", "别克", 300, "林荫大道");
motos[3] = new Car("京NT96968", "别克", 600, "GL8");
motos[4] = new Bus("京6566754", "金杯", 800,16 );
motos[5] = new Bus("京8696997", "金龙", 800,16 );
motos[6] = new Bus("京9696996", "金杯", 1500,34 );
motos[7] = new Bus("京8696998", "金龙", 1500,34 );
public MotoVehicle motoLeaseOut(String brand, String model, int seats) {
for (MotoVehicle mymoto : motos) {
if (mymoto instanceof Car) {
if (car.getBrand().equals(brand) && car.getModel().equals(model)) {
if (bus.getBrand().equals(brand) && bus.getSeats() == seats) {
public class Bus extends MotoVehicle {
public Bus(String numberPlate, String brand, double dailyRent, int seats) {
super(numberPlate, brand, dailyRent);
public void setSeats(int seats) {
public double calRent(int days){
double price=this.getDailyRent()*days;
} else if (days>=3&&days<7){
} else if (days>=7&&days<30) {
} else if (days>=30&&days<150) {
public class Car extends MotoVehicle {
public Car(String numberPlate, String brand, double dailyRent, String model) {
super(numberPlate, brand, dailyRent);
public String getModel() {
public void setModel(String model) {
public double calRent(int days){
double price=this.getDailyRent()*days;
}else if(days>7&&days<=30){
}else if(days>30&&days<=150){
import java.util.Scanner;
public class RentMgrSys {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
MotoOperation motoMgr=new MotoOperation();
System.out.println("*****欢迎光临租赁公司*****");
System.out.print("请选择你要租赁的汽车类型:");
int motoType=sc.nextInt();
System.out.println("请选择你要租赁的汽车品牌:1、别克 2、宝马");
int choose2=sc.nextInt();
System.out.println("请选择你要租赁的汽车类型:1、林荫大道2、GL8");
type=(sc.nextInt()==1)?"林荫大道":"GL8";
System.out.println("请选择你要租赁的汽车类型:1、X6 2、550i");
type=(sc.nextInt()==1)?"X6":"550i";
} else if (motoType==2) {
System.out.println("请选择你要租赁的汽车品牌:1、金龙 2、金杯");
brand=(sc.nextInt()==1)?"金龙":"金杯";
System.out.println("请选择你要租赁的汽车座位数:1、16座2、34座");
seats=(sc.nextInt()==1)?16:34;
moto =motoMgr.motoLeaseOut(brand,type,seats);
System.out.println("请选择你要租赁的天数:");
double money=moto.calRent(days);
System.out.println("租车成功,请拿车牌号去取车:"+moto.getVehicleId);
System.out.println("需要支付:"+money+"元");
