car class java

Solutions on MaxInterview for car class java by the best coders in the world

showing results for - "car class java"
Federico
15 Jun 2020
1public class Car {
2    private boolean engine = true;
3    private String model;
4    private int wheels = 4;
5    private int cylinder;
6    private int doors = 4;
7    private int speed;
8    private int maxspeed ;
9
10    public Car(boolean engine, String model, int wheels, int cylinder, int doors, int speed,int maxspeed) {
11        this.engine = engine;
12        this.model = model;
13        this.wheels = wheels;
14        this.cylinder = cylinder;
15        this.doors = doors;
16        this.speed = speed;
17        this.maxspeed = maxspeed;
18    }
19    public void TurnOnOffEngine(boolean turn){
20        if(turn){
21            this.engine = true;
22            System.out.println("Your start your engine");
23        }System.out.println("Your engine is off");
24
25    }
26
27    public int Accelerate(int acceleration,int maxspeed){
28        if(this.speed > 0 && this.speed<maxspeed)
29        {
30            this.speed += speed;
31        }else
32        {
33            System.out.println("Illegal speed limit");
34            if(acceleration>0)
35            {
36                System.out.println("you still have " + acceleration + " to reach your maximum speed");
37            }
38        }
39        return this.speed;
40    }
41    public void stopEngine(){
42        engineMode();
43    }
44    public void startEngine(){
45        engineMode();
46    }
47    private void engineMode() {
48        System.out.println("your engine mode is");
49        if(this.engine == true){
50            System.out.println("ON");
51        }else{
52            System.out.println("OFF");
53        }
54    }
55
56    public void setSpeed(int speed,int maxspeed) {
57        if(this.speed+speed < maxspeed){
58            this.speed += speed;
59            System.out.println("Your speed now is "+ this.speed);
60        }else{
61            System.out.println("Speed out of limits");
62        }
63
64
65    }
66
67    public int getSpeed() {
68        return speed;
69    }
70
71    public void breakCar(int speed){
72        if(this.speed > speed){
73            this.speed -= speed;
74            System.out.println("Car has slow down,your speed now is "+this.speed);
75        }else if(this.speed-speed <= 0){
76            System.out.println("your car has stopped ");
77        }
78
79
80    }
81    public boolean getEngine() {
82        return engine;
83    }
84
85    public void setEngine(boolean engine) {
86        this.engine = engine;
87    }
88
89    public String getModel() {
90        return model;
91    }
92
93    public void setModel(String model) {
94        this.model = model;
95    }
96
97    public int getWheels() {
98        return wheels;
99    }
100
101    public void setWheels(int wheels) {
102        this.wheels = wheels;
103    }
104
105    public int getCylinder() {
106        return cylinder;
107    }
108
109    public void setCylinder(int cylinder) {
110        this.cylinder = cylinder;
111    }
112
113    public int getDoors() {
114        return doors;
115    }
116
117    public void setDoors(int doors) {
118        this.doors = doors;
119    }
120}
121