定义card类 java_CarD.java

package bdqn;

//汽车类

/*定义汽车类(Car),有品牌(brand)、座位数(seatCount)、排量(displacement),油量(oilAmount)等属性。

有启动(start)、行驶(run)、刹车(brake)、加速(speedUp)、停止(stop)等方法,

汽车在启动时,行驶中油量会逐步减少,当油量是0时汽车无法启动、行驶。用面向对象的思想模拟这个过程。(测试数据信息自定)。*/

public class CarD {

String brand;

int seatCount;

String displacement;

int oilAmount;

// 显示车辆信息

public CarD(String brand, int seatCount, String displacement, int oilAmount) {

this.brand = brand;

this.seatCount = seatCount;

this.displacement = displacement;

this.oilAmount = oilAmount;

System.out.println("品牌:" + this.brand + "座位数:" + this.seatCount + ",排量为:" + this.displacement + ",油量:"

+ this.oilAmount + "升。");

}

// 启动方法

public void start() {

System.out.println("这辆" + this.brand + "在启动");

}

// 行驶方法

public void run(int oilAmount) {

if (oilAmount == 0) {

System.out.println("当油量为0时,这辆" + this.brand + "牌轿车无法行驶!");

}

}

// 刹车方法

public void brake() {

System.out.println("这辆" + this.brand + "牌轿车的刹车性能良好");

}

// 加速方法

public void speedUp() {

System.out.println("这辆" + this.brand + "牌轿车正在加速!");

}

// 停止方法

public void stop() {

System.out.println("这辆" + this.brand + "牌轿车停车熄火了!");

}

}

一键复制

编辑

Web IDE

原始数据

按行查看

历史

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值