-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEngine.java
More file actions
51 lines (40 loc) · 953 Bytes
/
Engine.java
File metadata and controls
51 lines (40 loc) · 953 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
//Engine.java
//The class creates an Engine object that initilizes the engine type, MPG of the engine, and max speed
public class Engine {
private String engineType;
private int mpg;
private int maxSpeed;
public Engine(String engineType, int mpg, int maxSpeed) {
if (engineType.length() == 0) {
this.engineType = "Generic engine";
}
else {
this.engineType = engineType;
}
if (mpg <= 0) {
this.mpg = 0;
}
else {
this.mpg = mpg;
}
if (maxSpeed <= 0) {
this.maxSpeed = 0;
}
else {
this.maxSpeed = maxSpeed;
}
}
public String getDescription() {
String describe = engineType + "(MPG: " + String.valueOf(mpg) + ", Max Speed: " + String.valueOf(maxSpeed) +")";
return describe;
}
public String getEngineType() {
return engineType;
}
public int getMpg() {
return mpg;
}
public int getMaxSpeed() {
return maxSpeed;
}
}