-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathEngine.java
More file actions
45 lines (36 loc) · 1013 Bytes
/
Engine.java
File metadata and controls
45 lines (36 loc) · 1013 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
public class Engine {
private FuelType ft;
private Double cfl;
private Double mfl;
// initalizing attritbutes for Engine class
public Engine(FuelType ft, Double cfl, Double mfl) {
this.ft = ft;
this.cfl = cfl;
this.mfl = mfl;
}
//setting fuel to refill to be at max
private void refuel(){
this.cfl= this.mfl;
}
// controls movement of thr train
private boolean go(){
this.cfl -= 3;
System.out.println(this.cfl);
if(this.cfl <= 0){
return false;
}
else{
return true;
}
}
// makes the train move
public static void main(String[] args) {
Engine myEngine = new Engine(FuelType.ELECTRIC, 100.0, 200.0);
while (myEngine.go()) {
// when it returns true
System.out.println("Choo choo!");
}
// when it returns false
System.out.println("Out of fuel.");
}
}