-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMain.java
40 lines (31 loc) · 1.19 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
import border.Citizen;
import border.Identifiable;
import border.Robot;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String inputOrEnd = scanner.nextLine();
List<Identifiable> identifiables = new ArrayList<>();
while (!"End".equalsIgnoreCase(inputOrEnd)){
String[] split = inputOrEnd.split("\\s+");
String nameOrModel = split[0];
if(split.length==2){ // create robot
Robot robot = new Robot(split[1],nameOrModel);
identifiables.add(robot);
}else { // create citizen
Citizen citizen = new Citizen(nameOrModel,Integer.parseInt(split[1]),split[2]);
identifiables.add(citizen);
}
inputOrEnd = scanner.nextLine();
}
String fake = scanner.nextLine();
for (Identifiable identifiable : identifiables) {
if(identifiable.getId().endsWith(fake)){
System.out.println(identifiable.getId());
}
}
}
}