package cars;
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 seatCount, int perRent) {
super ( vehicleId, brand, perRent) ;
this . seatCount= seatCount;
}
public float calRent ( 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;
}
}
package cars;
import java. util. *;
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) {
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;
}
}
package cars;
public abstract class MotoVehicle {
private String vehicleId;
private String brand;
private int perRent;
public abstract float calRent ( int days) ;
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;
}
}
package manage;
import cars. Bus;
import cars. Car;
import cars. MotoVehicle;
public class MotoOperation {
public MotoVehicle motos[ ] = new MotoVehicle [ 8 ] ;
public void init ( ) {
motos[ 0 ] = new Car ( "L京NY28588" , "宝马" , "X6" , 800 ) ;
motos[ 1 ] = new Car ( "L京CNY3284" , "宝马" , "550i" , 600 ) ;
motos[ 2 ] = new Car ( "L京NT37465" , "别克" , "林荫大道" , 300 ) ;
motos[ 3 ] = new Car ( "L京NT96968" , "别克" , "GL8" , 600 ) ;
motos[ 4 ] = new Bus ( "L京6566754" , "金龙" , 16 , 800 ) ;
motos[ 5 ] = new Bus ( "L京8696997" , "金杯" , 16 , 800 ) ;
motos[ 6 ] = new Bus ( "L京9696984" , "金龙" , 34 , 1500 ) ;
motos[ 7 ] = new Bus ( "L京8696918" , "金杯" , 34 , 1500 ) ;
}
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 ( ) . 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 cn. pb. manage;
import java. util. Scanner;
import cn. pb. cars. MotoVehicle;
public class RentMgrSys {
public static void main ( String[ ] args) {
Scanner input= new Scanner ( System. in) ;
MotoOperation motoMgr= new MotoOperation ( ) ;
motoMgr. init ( ) ;
MotoVehicle moto= null;
System. out. println ( "***********欢迎光临腾飞汽车租赁公司***********" ) ;
System. out. println ( "1、轿车 \t2、客车" ) ;
System. out. print ( "请选择你要租赁的汽车类型:" ) ;
int motoType= input. nextInt ( ) ;
String brand= "" ;
String type= "" ;
int seat= 0 ;
if ( motoType== 1 ) {
System. out. print ( "请选择你要租赁的汽车品牌:1、别克 2、宝马" ) ;
int choose2= input. nextInt ( ) ;
if ( choose2== 1 ) {
brand= "别克" ;
System. out. print ( "请选择你要租赁的汽车类型:1、林荫大道 2、GL8" ) ;
type= ( input. nextInt ( ) == 1 ) ? "林荫大道" : "GL8" ;
} else if ( choose2== 2 ) {
brand= "宝马" ;
System. out. print ( "请选择你要租赁的汽车类型:1、X6 2、550i" ) ;
type= ( input. nextInt ( ) == 1 ) ? "X6" : "550i" ;
}
} else if ( motoType== 2 ) {
type= "" ;
System. out. print ( "请选择你要租赁的汽车品牌:1、金龙 2、金杯" ) ;
brand= ( input. nextInt ( ) == 1 ) ? "金龙" : "金杯" ;
System. out. print ( "请选择你要租赁的汽车座位数:1、16座 2、34座" ) ;
seat= ( input. nextInt ( ) == 1 ) ? 16 : 34 ;
}
moto= motoMgr. motoLeaseOut ( brand, type, seat) ;
System. out. print ( "请输入您要租赁的天数:" ) ;
int days= input. nextInt ( ) ;
double money= moto. calRent ( days) ;
System. out. println ( "分配给您的汽车牌号是:" + moto. getVehicleId ( ) ) ;
System. out. println ( "您需要支付的租赁费用是:" + money+ "元。" ) ;
}
}