JavaOOP 继承实现汽车租赁计算价格

该博客介绍了如何使用Java编程实现汽车租赁系统的计费功能。通过一个抽象类`MotoVehicle`表示汽车,`Bus`和`Car`类分别继承自`MotoVehicle`,并实现了不同的计费策略。程序通过用户输入选择汽车类型、品牌、型号或座位数,计算相应的租赁价格。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

package cn.hello.test5;

/**
 * 客车类,继承汽车类。
 * @author 北大青鸟
 */
public final class Bus extends MotoVehicle {
	private int seatCount;// 座位数
	public Bus() {
	}
	public Bus(String no, String brand, int seatCount) {
		super(no, brand);
		this.seatCount = seatCount;
	}
	public int getSeatCount() {
		return seatCount;
	}
	public void setSeatCount(int seatCount) {
		this.seatCount = seatCount;
	}
	/**
	 * 计算客车租赁价
	 */
	public int calRent(int days) {
		if (seatCount <= 16) {
			return days * 800;
		} else {
			return days * 1500;
		}
	}
}
package cn.hello.test5;

/**
 * 轿车类,继承汽车类。
 * @author 北大青鸟
 */
public final class Car extends MotoVehicle {
	private String type;// 汽车型号
	public Car() {
	}
	public Car(String no, String brand, String type) {
		super(no, brand);
		this.type = type;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	/**
	 * 计算轿车租赁价
	 */
	public int calRent(int days) {
		if ("1".equals(ty
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值