java计算租金

这篇博客主要介绍了如何利用Java编程语言来实现租金计算的功能,包括可能涉及的逻辑和算法。

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

1.程序

package Demo1;

abstract class MotoVehicle{
	private String No;
	private String Brand;
	private String Color;
	private String Mileage;

	public String getNo() {
		return No;
	}
	public void setNo(String no) {
		No = no;
	}
	public String getBrand() {
		return Brand;
	}
	public void setBrand(String brand) {
		Brand = brand;
	}
	public String getColor() {
		return Color;
	}
	public void setColor(String color) {
		Color = color;
	}
	public String getMileage() {
		return Mileage;
	}
	public void setMileage(String mileage) {
		Mileage = mileage;
	}

	public MotoVehicle() {
		super();
	}
	public MotoVehicle(String no, String brand, String color, String mileage
		) {
		super();
		No = no;
		Brand = brand;
		Color = color;
		Mileage = mileage;
		//Cost = cost;
	}
	
	abstract void CalcRent();
	
	
}

class Car extends MotoVehicle{
	private String Type;
	private int Cost;

	public int getCost() {
		return Cost;
	}

	public void setCost(int cost) {
		Cost = cost;
	}

	public String getType() {
		return Type;
	}

	public void setType(String type) {
		Type = type;
	}

	public Car() {
		super();
	}

	public Car(String type) {
		super();
		Type = type;
	}

	public Car(String no, String brand, String color, String mileage,String type,int Cost) {
		super(no, brand, color, mileage);
		Type = type;
		Cost=getCost();
	}
	void CalcRent() {
		System.out.println(getNo()+","+Type);
		if(getNo().equalsIgnoreCase("GL8")&&Type.equalsIgnoreCase("别克商务舱")){
			Cost=600;
		}else if(getNo().equalsIgnoreCase("550i")&&Type.equalsIgnoreCase("宝马")){
			Cost=500;
		}else{
			Cost=300;
		}
		System.out.println(getNo()+","+getBrand()+","+getColor()+","+getMileage()+","+Cost+","+Type);
	}
	
}
class Bus extends MotoVehicle{
	private int SeatCount;
	private int Cost;
	
	public int getCost() {
		return Cost;
	}

	public void setCost(int cost) {
		Cost = cost;
	}

	public int getSeatCount() {
		return SeatCount;
	}

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

	public Bus() {
		super();
	}

	public Bus(int seatCount) {
		super();
		SeatCount = seatCount;
	}

	public Bus(String no, String brand, String color, String mileage,
			int SeatCount,int cost) {
		super(no, brand, color, mileage);
		SeatCount = getSeatCount();
		Cost=getCost();
	}
	
	void CalcRent() {
		if(getBrand().equalsIgnoreCase("客车")&&getSeatCount()<=16){
			Cost=800;
		}else{
			Cost=1500;
		}
		System.out.println(getNo()+","+getBrand()+","+getColor()+","+getMileage()+","+SeatCount+","+Cost);
	}
	
}
public class Test1 {

	public static void main(String[] args) {
		Car c1=new Car("GL8", "轿车", "银灰色", "30/1", "别克商务舱",600);
		c1.CalcRent();
		System.out.println();
		Car c2=new Car("550i", "轿车", "黑色", "60/1", "宝马",500);
		c2.CalcRent();
		System.out.println();
		Car c3=new Car("GL1", "轿车", "黄色", "60/1", "别克林荫大道",300);
		c3.CalcRent();
		System.out.println();
		Bus b1=new Bus("1", "客车", "黄色", "30/1", 20, 1500);
		b1.CalcRent();
		System.out.println();
		Bus b2=new Bus("2", "客车", "蓝色", "20/1", 16, 800);
		b2.CalcRent();
	}

}




2.截图


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值