Advertisement
Guest User

cOdE

a guest
Nov 14th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.42 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5. public static void main(String[] args) {
  6. // Scanner input = new Scanner("1\n" + "hi\n" + "4\n" + "1\n" + "hi2\n" + "8\n" +
  7. // "2\n" + "hi\n" + "jfk\n" + "ldn\n" + "2\n" + "hi2\n" + "ghk\n" + "tre\n" + "2\n" +
  8. // "hi2\n" + "AAA\n" + "BBB\n" +"x\n" + "2\n" + "x\n");
  9. Scanner input = new Scanner(System.in);
  10. AirportPanel panel = new AirportPanel(input);
  11. panel.Start();
  12.  
  13.  
  14. }
  15. }
  16.  
  17.  
  18.  
  19.  
  20. import java.util.ArrayList;
  21. import java.util.HashMap;
  22. import java.util.Scanner;
  23.  
  24. public class AirportPanel {
  25. private Scanner reader;
  26. private HashMap<String, String> planeHash = new HashMap<String, String>();
  27. private ArrayList<Flights> flightlist = new ArrayList<Flights>();
  28. private FlightService service;
  29.  
  30. public AirportPanel(Scanner reader) {
  31. this.reader = reader;
  32. }
  33.  
  34. public void Start() {
  35. System.out.println("Airport panel\n" +
  36. "--------------------\n");
  37. airportPanelLoop();
  38. }
  39.  
  40.  
  41. public void airportPanelLoop() {
  42. while (true) {
  43. options();
  44. String entered = reader.nextLine();
  45. if (entered.contains("1")) {
  46. addPlane();
  47. }
  48. if (entered.contains("2")) {
  49. addFlight();
  50. }
  51. if (entered.contains("x")) {
  52. exit();
  53. service.start();
  54. break;
  55. }
  56. }
  57. }
  58.  
  59. public void exit() {
  60. FlightService service = new FlightService(reader, planeHash, flightlist);
  61. this.service = service;
  62. }
  63.  
  64. public void options() {
  65. System.out.println("Choose operation:\n [1] Add airplane\n [2] Add flight\n [x] Exit");
  66. }
  67.  
  68. public void addPlane() {
  69. System.out.println("Give plane ID: ");
  70. String id = reader.nextLine();
  71. System.out.println("Give plane capacity: ");
  72. String capa = reader.nextLine();
  73. planeHash.put(id, capa);
  74. }
  75.  
  76. public void addFlight() {
  77. System.out.println("Give plane ID: ");
  78. String id = reader.nextLine();
  79. System.out.println("Give departure airport code: ");
  80. String dep = reader.nextLine();
  81. System.out.println("Give destination airport code: ");
  82. String des = reader.nextLine();
  83. Flights aFlight = new Flights(id, dep, des);
  84. flightlist.add(aFlight);
  85. }
  86.  
  87.  
  88. }
  89.  
  90.  
  91.  
  92.  
  93. import java.util.ArrayList;
  94. import java.util.HashMap;
  95. import java.util.Map;
  96. import java.util.Scanner;
  97.  
  98. public class FlightService {
  99. private Scanner reader;
  100. private HashMap<String, String> planeHash;
  101. private ArrayList<Flights> flightlist;
  102.  
  103. public FlightService(Scanner reader, HashMap<String, String> planeHash,
  104. ArrayList<Flights> flightlist) {
  105. this.reader = reader;
  106. this.planeHash = planeHash;
  107. this.flightlist = flightlist;
  108. }
  109.  
  110. public void start() {
  111. System.out.println("Flight service\n" + "------------\n");
  112. flightServiceLoop();
  113. }
  114.  
  115. public void flightServiceLoop() {
  116. while (true) {
  117. options();
  118. String entered = reader.nextLine();
  119. if (entered.contains("1")) {
  120. printPlanes();
  121. }
  122. if (entered.contains("2")) {
  123. printFlights();
  124. }
  125. if (entered.contains("3")) {
  126. printPlaneInfo();
  127. }
  128. if (entered.contains("x")) {
  129. break;
  130. }
  131. }
  132. }
  133.  
  134. public void printPlanes() {
  135. for (Map.Entry i : planeHash.entrySet()) {
  136. String key = (String) i.getKey();
  137. String value = (String) i.getValue();
  138.  
  139. System.out.println(key + " (" + value + " ppl)");
  140. }
  141.  
  142. }
  143.  
  144. public void printFlights() {
  145. for (Flights f : flightlist) {
  146. String dep = f.departure;
  147. String des = f.destination;
  148. String key = f.id;
  149. String value = planeHash.get(f.id);
  150. System.out.println(key + " (" + value + " ppl)" + " (" + dep + "-" + des + ")");
  151. }
  152. //HA-LOL (42 ppl) (HEL-BAL)
  153.  
  154. // for (Map.Entry i : planeHash.entrySet()) {
  155. // for (Flights f : flightlist) {
  156. //
  157. // String key = (String)i.getKey();
  158. // String value = (String)i.getValue();
  159. // String dep = f.departure;
  160. // String des = f.destination;
  161. // System.out.println(key + " (" + value + " ppl)" + " (" + dep + "-" + des + ")");
  162. // }
  163. // }
  164. }
  165.  
  166. public void printPlaneInfo() {
  167. System.out.println("Give plane ID: ");
  168. String search = reader.nextLine();
  169. if (planeHash.containsKey(search)) {
  170. System.out.println(search + " (" + planeHash.get(search) + " ppl)");
  171. }
  172. }
  173.  
  174.  
  175. public void options() {
  176. System.out.println("Choose operation:\n" + "[1] Print planes\n" + "[2] Print flights\n" +
  177. "[3] Print plane info\n" + "[x] Quit");
  178. }
  179.  
  180.  
  181. }
  182.  
  183.  
  184.  
  185.  
  186. public class Flights {
  187.  
  188. public String id;
  189. public String departure;
  190. public String destination;
  191.  
  192. public Flights(String id, String dep, String des) {
  193. this.id = id;
  194. this.departure = dep;
  195. this.destination = des;
  196. }
  197.  
  198.  
  199.  
  200. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement