Untitled
unknown
plain_text
2 years ago
1.2 kB
5
Indexable
Never
class Car { private String name; private boolean engine; private int wheels; private int cylinders; private int initialSpeed; public Car(String name, int cylinders) { this.name = name; this.cylinders = cylinders; this.engine = true; this.wheels = 4; this.initialSpeed = 0; } public String getName() { return name; } public boolean isEngine() { return engine; } public int getWheels() { return wheels; } public int getCylinders() { return cylinders; } public void startEngine () { System.out.println("The engine has started"); } public void accelerate(int speed) { startEngine(); System.out.println("The car is accelerated with " + speed + " km/h"); initialSpeed=+ speed; System.out.println("The car is moving with " + this.initialSpeed + " km/h"); } public class Main { public static void main(String[] args) { Car car = new Car("Tesla", 4); car.accelerate(50); car.accelerate(50); } }