-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment part 1
More file actions
55 lines (47 loc) · 1.21 KB
/
Assignment part 1
File metadata and controls
55 lines (47 loc) · 1.21 KB
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
53
54
55
public class Manager {
public static void main(String[] args) {
Driver John = new Driver("John");
John.getGoing();
}
}
class Car {
private boolean isRunning;
public boolean startCar() {
isRunning = true;
System.out.println("The car has started.");
return true;
}
public boolean stopCar() {
isRunning = false;
System.out.println("The car has stopped.");
return true;
}
public void honkHorn() {
if (isRunning) {
System.out.println("Honk! Honk!");
} else {
System.out.println("Cannot honk. The car is not running.");
}
}
}
class Driver {
private String name;
private Car Tesla;
public Driver(String name) {
this.name = name;
Tesla = new Car();
}
public void getGoing() {
Tesla.startCar();
System.out.println(name + " is driving the car.");
// Simulate driving for 5 seconds
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Tesla.stopCar();
System.out.println(name + " has stopped the car.");
Tesla.honkHorn();
}
}