java汽车租赁系统的简单应用

1.题目内容及要求
在这里插入图片描述
2. 代码实现

(1)main方法

package com.lut.rent;

import java.util.Scanner;

public class TestRent {

	public static void main(String[] args) {
		String no, brand, mytype, type, seatCount;
		int x, days, rent;
		int money = 0;
		Car car;
		Bus bus;
		Scanner input = new Scanner(System.in);
		System.out.println("欢迎来到汽车租赁公司!");
		System.out.println("请输入要租赁的汽车种类:");
		x = input.nextInt();
		for (int i = 1; i <= x; i++) {
			System.out.println("请输入第" + i + "种车要租赁的天数:");
			days = input.nextInt();
			System.out.println("请输入要租赁的汽车类型(1:轿车  2:客车)");
			mytype = input.next();
			if ("1".equals(mytype)) {
				System.out.println("请输入要租的汽车品牌(1:宝马  2:别克)");
				brand = input.next();
				System.out.println("请输入汽车的型号");
				if ("1".equals(brand)) {
					System.out.println("宝马车(1:550i)");
				} else {
					System.out.println("别克车 (2:商务舱GL8  3:林荫大道)");
				}
				type = input.next();

				car = new Car(brand, type);
				rent = car.calRent(days);
			} else {
				System.out.println("请输入要租的客车品牌(1:金杯  2:金龙)");
				brand = input.next();
				System.out.println("请输入客车座位数的类型:(1:<=16座   2: >16座)");
				seatCount = input.next();

				bus = new Bus(brand, seatCount);
				rent = bus.calRent(days);
			}
			System.out.println("顾客您好,您需要支付的第" + i + "种车费用是" + rent + "。");

			money = money + rent;

		}
		System.out.println("顾客您好,您需要支付的车辆的总费用是" + money + "元。");
	}

}

(2) 父类

package com.lut.rent;

public abstract class MotoVehicle {

	private String brand

	public MotoVehicle() {
	}

	public MotoVehicle(String brand) {

		this.brand = brand;
	}

	 public abstract int calRent(int days);

}

(3)Car子类

package com.lut.rent;

public final class Car extends MotoVehicle {

	private String type;

	public Car() {

	}

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

	public String getType() {
		return type;
	}

	public int calRent(int days) {
		if ("1".equals(type)) {
			return days * 500;

		} else if ("2".equals(type)) {
			return days * 600;

		} else {
			return days * 300;
		}

	}

}

(4)Bus子类

package com.lut.rent;

public final class Bus extends MotoVehicle {

	private String seatCount;

	public Bus() {

	}

	public Bus(String brand, String seatCount) {
		super(brand);
		this.seatCount = seatCount;
	}

	public String getType() {
		return seatCount;
	}

	public int calRent(int days) {
		if ("1".equals(seatCount)) {
			return days * 800;
		} else {
			return days * 1500;
		}

	}

}

3.输出实例

欢迎来到XXX汽车租赁公司!
请输入要租赁的汽车种类:
2
请输入第1种车要租赁的天数:
10
请输入要租赁的汽车类型(1:轿车  2:客车)
1
请输入要租的汽车品牌(1:宝马  2:别克)
1
请输入汽车的型号
宝马车(1550i)
1
顾客您好,您需要支付的第1种车费用是5000。
请输入第2种车要租赁的天数:
5
请输入要租赁的汽车类型(1:轿车  2:客车)
2
请输入要租的客车品牌(1:金杯  2:金龙)
2
请输入客车座位数的类型:(1<=162: >16座)
2
顾客您好,您需要支付的第2种车费用是7500。
顾客您好,您需要支付的车辆的总费用是12500元。
  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值