Java带你去看流浪世界!(十三-小程序)

package cars;
/**
 * 
 * @author Li_BetterMen
 *
 */
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;
/**
 * 
 * @author Li_BetterMen
 *
 */
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;
/**
 * 
 * @author Li_BetterMen
 *
 */
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;
/**
 * 
 * @author Li_BetterMen
 *
 */
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;
/**
 * 
 * @author Li_BetterMen
 *
 */
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+"元。");
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值