编写汽车租赁系统

编写测试类


import java.util.Scanner;

public class TestMotoVehicle {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		System.out.println("欢迎来到汽车租赁公司");
		System.out.println("请输入需要租赁的天数");
		int days = sc.nextInt();
		System.out.println("请选择汽车类型(1,轿车 2,客车)");
		int choose = sc.nextInt();
		switch (choose) {
		case 1:
			System.out.println("请输入汽车品牌(1,宝马2,别克)");
			choose = sc.nextInt();
			if (choose == 1) {
				Car car = new Car("5501", 8895, "宝马");

				System.out.println("租金是" + car.calRent(days));
				car.show();
			} else if (choose == 2) {
				System.out.println("请选择型号(1,商务舱GL8  2,林荫大道)");
				choose = sc.nextInt();
				Car car = new Car("商务舱GL8", 8895, "别克");
				System.out.println("租金是" + car.calRent(days));
				car.show();
			} else {
				Car car = new Car("林荫大道", 8879, "别克");
				System.out.println("租金是" + car.calRent(days));
				car.show();
			}
			break;
		case 2:
			System.out.println("请选择座位数");
			choose = sc.nextInt();
			if (choose == 1) {
				Bus b = new Bus(54865, "金杯", 15);
				System.out.println("租金是" + b.calRent(days));
				b.show();
			} else if (choose == 2) {
				Bus b = new Bus(54865, "金龙", 25);
				System.out.println("租金是" + b.calRent(days));
				b.show();
			}
			break;
		default:
			break;
		}

	}

}

两种汽车类型的父类

public abstract class MotoVehicle {
	private int no; // 车牌号
	private String brand; // 品牌
	/*
	 * private String color; //颜色 private int Mileage; //里程 private String
	 * models;//表示型号 private int rental;//表示租金
	 */
	/*
	 * public void print(){
	 * System.out.println("你选择的是"+models+"日租金是"+rental+"元/天"); }
	 */

	public MotoVehicle(int no, String brand) {

		this.no = no;
		this.brand = brand;
	}

	public MotoVehicle() {

	}

	public int getNo() {
		return no;
	}

	public void setNo(int no) {
		no = no;
	}

	public String getBrand() {
		return brand;
	}

	public void setBrand(String brand) {
		brand = brand;
	}

	public abstract int calRent(int days);
}

创建子类car


public class Car extends MotoVehicle {
	private String type;

	public Car() {

	}

	public Car(String type, int no, String brand) {
		super(no, brand);
		this.type = type;
	}

	public String getType() {
		return type;
	}

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

	public int calRent(int days) {
		int sum=0;
		if ("5501".equals(type)) {
			sum= days * 500;
		} else if ("商务舱GL8".equals(type)) {
			sum= days * 600;
		} else if("林荫大道".equals(type)){
			sum= days * 300;
		}
		return sum;

	}

	public void show() {
		System.out.println("车牌号是" + super.getNo());
	}

创建子类Bus

public class Bus extends MotoVehicle {
	private int SeatCount;

	public Bus() {
		super();
		// TODO Auto-generated constructor stub
	}

	public Bus(int no, String brand, int seatCount) {
		super(no, brand);
		SeatCount = seatCount;
	}

	public int getSeatCount() {
		return SeatCount;
	}

	public void setSeatCount(int seatCount) {
		SeatCount = seatCount;
	}

	public int calRent(int days) {
		int sum=0;
		if (SeatCount <= 16) {
			sum = days * 800;
		} else if(SeatCount>16){
			sum= days * 1500;
		}
		return sum;
	}

	public void show() {
		System.out.println("车牌号是" + super.getNo());
	}
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
YOLO高分设计资源源码,详情请查看资源内容中使用说明 YOLO高分设计资源源码,详情请查看资源内容中使用说明 YOLO高分设计资源源码,详情请查看资源内容中使用说明 YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值