「java汽车刹车」轿车的刹车
本篇文章给大家谈谈java汽车刹车,以及轿车的刹车对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
- 1、java程序:定义交通工具接口,在其中定义启动和刹车方法;然后定义汽车类和飞机类实现交通工具接口类;
- 2、买了辆java山地车,为什么工作人员说要两个刹车一起按?我的是碟刹。
- 3、如何用java设计接口完成加速,减速,刹车的功能
- 4、请问如何用Java编写一个汽车类Car
java程序:定义交通工具接口,在其中定义启动和刹车方法;然后定义汽车类和飞机类实现交通工具接口类;
除去测试,简单写一下你的程序。
public interface traffic {
void start();
void stop();
}
public class car implements traffic {
public void start() {
//这里写汽车启动
System.out.println("car is start");
}
public void stop() {
//这里写汽车停止
System.out.println("car is stop");
}
}
public class plane implements traffic {
public void start() {
//这里写飞机启动
System.out.println("plane is start");
}
public void stop() {
//这里写飞机停止
System.out.println("plane is stop");
}
}
买了辆java山地车,为什么工作人员说要两个刹车一起按?我的是碟刹。
呃,不知道A,更本没有这个规矩的,那个人新来的吧。你在平路2个刹车无所谓的,上坡先用前刹车后用后刹车,下坡一定要先用后刹,基本控制后用前刹制动。你自己以后会掌握出自己习惯的刹车方式,我们最初只是凭经验给你建议的。2刹车一起按有BUG的,比如下大坡时有翻车的可能。
如何用java设计接口完成加速,减速,刹车的功能
看你是往大作还是往小做,往小做的话就是抽象成累的行为,往大做就是车中有变速箱,变速箱包装行为方法,参照建造者模式,个人意见哈
请问如何用Java编写一个汽车类Car
public class Car {
private String color;//颜色
private int door;//车门数量
private float speed;//车速
public Car(){
this.color = "红色";
this.door = 3;
this.speed = 110;
}
public Car(String color, int door, float speed) {
this.color = color;
this.door = door;
this.speed = speed;
}
public void start(){
//汽车启动。输出汽车已启动,并输出汽车的各个属性
System.out.println("汽车已启动,汽车颜色为"+color+",车门数为"+door+",车速为"+speed);
}
public void speedUp(float speed){
//加速
System.out.println("汽车加速到"+speed+"km/h");
}
public void shutDown(float speed){
//减速
System.out.println("汽车减速到"+speed+"km/h");
}
public void brake(){
//刹车
System.out.println("已刹车");
}
}
public class Test {
public static void main(String[] args){
Car car = new Car();
car.start();
car.speedUp(100);
car.shutDown(60);
car.brake();
Car car1 = new Car("白色",4,20.2F);
car1.start();
car1.speedUp(100);
car1.shutDown(60);
car1.brake();
}
}
运行结果
关于java汽车刹车和轿车的刹车的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。
发布于:2022-12-27,除非注明,否则均为
原创文章,转载请注明出处。