-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
36 lines (33 loc) · 1.19 KB
/
Main.java
File metadata and controls
36 lines (33 loc) · 1.19 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
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Hero hero = new Hero();
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("Enter a transportation strategy (walk, ride, drive, fly) or 'exit' to quit:");
String strategy = scanner.nextLine();
switch (strategy.toLowerCase()) {
case "walk":
hero.setMovingStrategy(new Walking());
break;
case "ride":
hero.setMovingStrategy(new HorseRiding());
break;
case "drive":
hero.setMovingStrategy(new CarDriving());
break;
case "fly":
hero.setMovingStrategy(new PlaneFlying());
break;
case "exit":
System.out.println("Exiting...");
scanner.close();
return;
default:
System.out.println("Invalid strategy. Please try again.");
continue;
}
hero.move();
}
}
}