-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCar.java
More file actions
52 lines (44 loc) · 964 Bytes
/
Car.java
File metadata and controls
52 lines (44 loc) · 964 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
public class Car {
private int yearModel;
private String make;
private int speed;
static final int maxSpeed = 180;
static final int minSpeed = 0;
Car() {
yearModel = 0000;
make = " ";
speed = minSpeed;
}
Car(int year, String make) {
yearModel = year;
this.make = make;
speed = minSpeed;
}
public int getYearModel() {
return yearModel;
}
public String getMake() {
return make;
}
public int getSpeed() {
return speed;
}
public void accelerate() {
if (speed == maxSpeed) {
return;
} else {
speed += 5;
}
}
public void brake() {
if (speed == minSpeed) {
return;
} else {
speed -= 5;
}
}
@Override
public String toString() {
return String.format("%4d %-20s %3d", yearModel, make, speed);
}
}