deyanmalinov

5. Border Control

Jul 13th, 2020
630
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package DPM;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import java.util.Scanner;
  5. public class Main {
  6.     public static void main(String[] args){
  7.         Scanner scan = new Scanner(System.in);
  8.         List<Identifable> things = new ArrayList<>();
  9.         String lines;
  10.         while (true){
  11.             if ("End".equals(lines=scan.nextLine())){
  12.                 break;
  13.             }
  14.             String[] line=lines.split(" ");
  15.             Identifable identifable= null;
  16.             if (line.length==2){
  17.                 identifable=new Robot(line[0], line[1]);
  18.             }else if (line.length==3){
  19.                 identifable= new Citizen(line[0], Integer.parseInt(line[1]), line[2]);
  20.             }
  21.             things.add(identifable);
  22.         }
  23.         String fakeID = scan.nextLine();
  24.         things.stream().filter(identifable -> identifable.getId()
  25.                 .endsWith(fakeID))
  26.                 .forEach(identifable -> System.out.println(identifable.getId()));
  27.        }
  28. }-----------------------------------------------
  29. package DPM;
  30. public interface Identifable {
  31.     String getId();
  32. }-----------------------------------------------
  33. package DPM;
  34. public class Citizen implements Identifable {
  35.     private String name;
  36.     private int age;
  37.     private String id;
  38.     public Citizen(String name, int age, String id){
  39.         this.name=name;
  40.         this.age=age;
  41.         this.id=id;
  42.     }
  43.     @Override
  44.     public String getId() {
  45.         return this.id;
  46.     }
  47. }---------------------------------------
  48. package DPM;
  49. public class Robot implements Identifable {
  50.     private String model;
  51.     private String  id;
  52.     public Robot(String model, String id) {
  53.         this.model = model;
  54.         this.id = id;
  55.     }
  56.     @Override
  57.     public String getId() {
  58.         return this.id;
  59.     }
  60. }----------------------------------------
RAW Paste Data