Advertisement
Guest User

jedenplik

a guest
Feb 18th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.19 KB | None | 0 0
  1.  
  2. import java.util.*;
  3.  
  4. public class Main {
  5.  
  6.     public static void main(String[] args) {
  7.         Scanner reader = new Scanner(System.in);
  8.  
  9.         AiportPanel ui = new AiportPanel(reader);
  10.         ui.start();
  11.     }
  12. }
  13.  
  14. class Plains {
  15.  
  16.     private String id;
  17.     private int capacity;
  18.     private ArrayList<String> destinations = new ArrayList<String>();
  19.  
  20.     public Plains(String id, int capacity) {
  21.         this.id = id;
  22.         this.capacity = capacity;
  23.     }
  24.  
  25.     public void setDestination(String departure, String destination) {
  26.         String oneWord = departure + "-" + destination;
  27.         destinations.add(oneWord);
  28.     }
  29.  
  30.     public String id() {
  31.         return this.id;
  32.     }
  33.  
  34.     public String printPlanes() {
  35.         return this.id + " (" + this.capacity + " ppl)";
  36.     }
  37.  
  38.     public String printFlights() {
  39.         for (String dest : destinations) {
  40.             System.out.println(this.id + " (" + this.capacity + " ppl) (" + dest + ")");
  41.         }
  42.         return "";
  43.     }
  44. }
  45.  
  46. class AiportPanel {
  47.  
  48.         Scanner reader;
  49.         private ArrayList<Plains> planes;
  50.         int counter = 0;
  51.  
  52.         public AiportPanel(Scanner reader) {
  53.             this.reader = reader;
  54.             planes = new ArrayList<Plains>();
  55.         }
  56.  
  57.         public void start() {
  58.             System.out.println("Airport panel\n" + "--------------------\n");
  59.  
  60.             while (counter == 0) {
  61.                 System.out.print("Choose operation:\n"
  62.                         + "[1] Add airplane\n"
  63.                         + "[2] Add flight\n"
  64.                         + "[x] Exit\n"
  65.                         + "> ");
  66.  
  67.                 String readed = reader.nextLine();
  68.  
  69.                 if (readed.equals("1")) {
  70.                     System.out.print("Give plane ID: ");
  71.                     String planeID = reader.nextLine();
  72.                     System.out.print("Give plane capacity: ");
  73.                     int planeCapacity = Integer.parseInt(reader.nextLine());
  74.                     planes.add(new Plains(planeID, planeCapacity));
  75.                 }
  76.  
  77.                 if (readed.equals("2")) {
  78.                     System.out.print("Give plane ID: ");
  79.                     String planeID = reader.nextLine();
  80.                     System.out.print("Give departure airport code: ");
  81.                     String departure = reader.nextLine();
  82.                     System.out.print("Give destination airport code: ");
  83.                     String destination = reader.nextLine();
  84.                     for (Plains plain : planes) {
  85.                         if (planeID.equals(plain.id())) {
  86.                             plain.setDestination(departure, destination);
  87.                         }
  88.                     }
  89.                 }
  90.  
  91.                 if (readed.equals("x")) {
  92.                     System.out.println("\nFlight service\n" + "------------\n");
  93.                     counter++;
  94.                 }
  95.             }
  96.  
  97.             while (counter == 1) {
  98.                 System.out.print("Choose operation:\n"
  99.                         + "[1] Print planes\n"
  100.                         + "[2] Print flights\n"
  101.                         + "[3] Print plane info\n"
  102.                         + "[x] Quit\n"
  103.                         + "> ");
  104.                 String second = reader.nextLine();
  105.  
  106.                 if (second.equals("1")) {
  107.                     for (Plains plain : planes) {
  108.                         System.out.println(plain.printPlanes());
  109.                     }
  110.                 }
  111.  
  112.                 if (second.equals("2")) {
  113.                     for (Plains plain : planes) {
  114.                         System.out.println(plain.printFlights());
  115.                     }
  116.                 }
  117.  
  118.                 if (second.equals("3")) {
  119.                     System.out.println("Give plane ID: ");
  120.                     String id = reader.nextLine();
  121.                     for (Plains plane : planes) {
  122.                         if (id.equals(plane.id())) {
  123.                             System.out.println(plane.printPlanes());
  124.                         }
  125.                     }
  126.                 }
  127.  
  128.                 if (second.equals("x")) {
  129.                     counter++;
  130.                 }
  131.             }
  132.         }
  133.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement