-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.java
47 lines (41 loc) · 1.25 KB
/
Main.java
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
import java.io.Console;
import java.util.List;
import java.util.ArrayList;
import car.*;
class LocationAwareProductionSystem {
String location;
public LocationAwareProductionSystem(String location) {
this.location = location;
}
public Car produce() {
Car car = null;
if (location.equalsIgnoreCase("USA")) {
car = new USACar();
} else if (location.equalsIgnoreCase("Europe")) {
car = new EuropeanCar();
} else if (location.equalsIgnoreCase("Asia")) {
car = new AsianCar();
}
car.buildCar();
return car;
}
}
public class Main {
public static void main(String[] args) {
String location;
List<String> locations = new ArrayList<String>();
locations.add("USA");
locations.add("Europe");
locations.add("Asia");
Console console = System.console();
while (true) {
location = console.readLine("Enter location: ");
if (locations.contains(location)) {
break;
}
}
LocationAwareProductionSystem production_system = new LocationAwareProductionSystem(location);
Car car = production_system.produce();
car.printCar();
}
}