码迷,mamicode.com
首页 > 其他好文 > 详细

2019-1-22 汽车租赁

时间:2019-01-22 13:17:12      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:info   分享图片   http   string   dmi   技术   ceo   父类   on()   

package java_car_duotai;
/**
 * 车类,父类
 * @author Administrator
 */
public abstract class Car {
	private String model;//品牌型号
	private String no;//车牌号
	private double price;//日租金
	
	public Car() {}
	
	public Car(String model,String no,double price) {
		this.model = model;
		this.no = no;
		this.price = price;
	}
	
	public String getModel() {
		return model;
	}
	public void setModel(String model) {
		this.model = model;
	}
	public String getNo() {
		return no;
	}
	public void setNo(String no) {
		this.no = no;
	}
	public double getPrice() {
		return price;
	}
	public void setPrice(double price) {
		this.price = price;
	}
	
	public abstract double discount(int day);
	
}

  

package java_car_duotai;
/**
 * 客车类
 * @author Administrator
 */
public class Passenger extends Car {
	private int seat;//几座
	
	public Passenger() {}
	
	public Passenger(String model,String no,double price,int seat) {
		super(model,no,price);
		this.seat = seat;
	}

	public int getSeat() {
		return seat;
	}

	public void setSeat(int seat) {
		this.seat = seat;
	}
	
	//计算客车出折扣后的日租金
	public double discount(int day) {
		double money = 0;
		if(day>=150) {
			money = super.getPrice()*0.6;
		}else if(day>=30) {
			money = super.getPrice()*0.7;
		}else if(day>=7) {
			money = super.getPrice()*0.8;
		}else if(day>=3) {
			money = super.getPrice()*0.9;
		}else {
			money = super.getPrice();
		}
		return money;
	}
}

  

package java_car_duotai;
/**
 * 轿车类
 * @author Administrator
 */
public class Saloon extends Car {
	
	private String type;
	
	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public Saloon() {}
	
	public Saloon(String model,String no,double price,String type) {
		super(model,no,price);
		this.type = type;
	}
	
	//计算出轿车折扣后的日租金
		public double discount(int day) {
			double money = 0;
			if(day>=150) {
				money = super.getPrice()*0.7;
			}else if(day>=30) {
				money = super.getPrice()*0.8;
			}else if(day>=7) {
				money = super.getPrice()*0.9;
			}else {
				money = super.getPrice();
			}
			return money;
		}
}

  

package java_car_duotai;

public class ShowCar {

	Car sc[] = new Car[8];
    public void show() {
		sc[0] = new Passenger("金杯","京6566754",800.,16);
		sc[1] = new Passenger("金杯","京9696996",1500,34);
		sc[2] = new Passenger("金龙","京8696997",800,16);
		sc[3] = new Passenger("金龙","京8696998",1500,34);
		sc[4] = new Saloon("宝马","京NY28588",800,"X6");
		sc[5] = new Saloon("宝马","京CNY3284",600,"550i");
		sc[6] = new Saloon("别克","京NT37465",300,"林萌大道");
		sc[7] = new Saloon("别克","京NT96968",600,"GL8");
	}
    
    public Car selCar(String medol,String type,int seat) {
    	Car car = null;
    	for(Car c : sc) {
    		if(c instanceof Passenger) {
    			Passenger p = (Passenger)c;
    			if(p.getModel().equals(medol)&&p.getSeat()==seat) {
    				car = p;
    			}
    		}else if(c instanceof Saloon) {
    			Saloon s = (Saloon)c;
    			if(s.getModel().equals(medol)&&s.getType().equals(type)) {
    				car = s;
    			}
    		}
    	}
    	return car;
    }
}

  

package java_car_duotai;

import java.util.Scanner;

//客人类,选择车类弄
public class Test {
	public static void main(String[] args) {
		Scanner cxj = new Scanner(System.in);
		ShowCar sc = new ShowCar();
		Car cr = null;
		sc.show();
		System.out.print("请问您需要车类(1、轿车 2、客车):");
		int select = cxj.nextInt();
		String medol = null;
		String type = null;
		int seat = 0;
		if(select==1) {
			System.out.print("请选择车型(1、宝马\t2、别克):");
			int se = cxj.nextInt();
			if(se==1) {
				medol = "宝马";
				System.out.print("请选择型号(1、X6\t2、550i):");
				int a = cxj.nextInt();
				if(a==1) {
					type = "X6";
				}else {
					type = "550i";
				}
			}else {
				medol = "别克";
				System.out.print("请选择型号(1、林萌大道\t2、GL8):");
				int a = cxj.nextInt();
				if(a==1) {
					type = "林萌大道";
				}else {
					type = "GL8";
				}
			}
		}else {
			System.out.print("请选择车型(1、金龙\t2、金杯):");
			int se = cxj.nextInt();
			if(se==1) {
				medol = "金龙";
				System.out.print("请选择座数(1、16\t2、34):");
				int a = cxj.nextInt();
				if(a==1) {
					seat = 16;
				}else {
					seat = 34;
				}
			}else {
				medol = "金杯";
				System.out.print("请选择座数(1、16\t2、34):");
				int a = cxj.nextInt();
				if(a==1) {
					seat = 16;
				}else {
					seat = 34;
				}
			}
		}
		
		cr = sc.selCar(medol, type, seat);
		System.out.print("请问您要租几天:");
		int day = cxj.nextInt();
		double sum = cr.discount(day);
		System.out.println("折扣后日租金是:"+sum);
		System.out.println("给您安排的车的车牌号是:"+cr.getNo());
		System.out.println("总租金是:"+sum*day);	
	}
}

  结果示例:

技术分享图片

技术分享图片

 

2019-1-22 汽车租赁

标签:info   分享图片   http   string   dmi   技术   ceo   父类   on()   

原文地址:https://www.cnblogs.com/chenxj/p/10303122.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!