Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- // Scanner input = new Scanner("1\n" + "hi\n" + "4\n" + "1\n" + "hi2\n" + "8\n" +
- // "2\n" + "hi\n" + "jfk\n" + "ldn\n" + "2\n" + "hi2\n" + "ghk\n" + "tre\n" + "2\n" +
- // "hi2\n" + "AAA\n" + "BBB\n" +"x\n" + "2\n" + "x\n");
- Scanner input = new Scanner(System.in);
- AirportPanel panel = new AirportPanel(input);
- panel.Start();
- }
- }
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.Scanner;
- public class AirportPanel {
- private Scanner reader;
- private HashMap<String, String> planeHash = new HashMap<String, String>();
- private ArrayList<Flights> flightlist = new ArrayList<Flights>();
- private FlightService service;
- public AirportPanel(Scanner reader) {
- this.reader = reader;
- }
- public void Start() {
- System.out.println("Airport panel\n" +
- "--------------------\n");
- airportPanelLoop();
- }
- public void airportPanelLoop() {
- while (true) {
- options();
- String entered = reader.nextLine();
- if (entered.contains("1")) {
- addPlane();
- }
- if (entered.contains("2")) {
- addFlight();
- }
- if (entered.contains("x")) {
- exit();
- service.start();
- break;
- }
- }
- }
- public void exit() {
- FlightService service = new FlightService(reader, planeHash, flightlist);
- this.service = service;
- }
- public void options() {
- System.out.println("Choose operation:\n [1] Add airplane\n [2] Add flight\n [x] Exit");
- }
- public void addPlane() {
- System.out.println("Give plane ID: ");
- String id = reader.nextLine();
- System.out.println("Give plane capacity: ");
- String capa = reader.nextLine();
- planeHash.put(id, capa);
- }
- public void addFlight() {
- System.out.println("Give plane ID: ");
- String id = reader.nextLine();
- System.out.println("Give departure airport code: ");
- String dep = reader.nextLine();
- System.out.println("Give destination airport code: ");
- String des = reader.nextLine();
- Flights aFlight = new Flights(id, dep, des);
- flightlist.add(aFlight);
- }
- }
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.Scanner;
- public class FlightService {
- private Scanner reader;
- private HashMap<String, String> planeHash;
- private ArrayList<Flights> flightlist;
- public FlightService(Scanner reader, HashMap<String, String> planeHash,
- ArrayList<Flights> flightlist) {
- this.reader = reader;
- this.planeHash = planeHash;
- this.flightlist = flightlist;
- }
- public void start() {
- System.out.println("Flight service\n" + "------------\n");
- flightServiceLoop();
- }
- public void flightServiceLoop() {
- while (true) {
- options();
- String entered = reader.nextLine();
- if (entered.contains("1")) {
- printPlanes();
- }
- if (entered.contains("2")) {
- printFlights();
- }
- if (entered.contains("3")) {
- printPlaneInfo();
- }
- if (entered.contains("x")) {
- break;
- }
- }
- }
- public void printPlanes() {
- for (Map.Entry i : planeHash.entrySet()) {
- String key = (String) i.getKey();
- String value = (String) i.getValue();
- System.out.println(key + " (" + value + " ppl)");
- }
- }
- public void printFlights() {
- for (Flights f : flightlist) {
- String dep = f.departure;
- String des = f.destination;
- String key = f.id;
- String value = planeHash.get(f.id);
- System.out.println(key + " (" + value + " ppl)" + " (" + dep + "-" + des + ")");
- }
- //HA-LOL (42 ppl) (HEL-BAL)
- // for (Map.Entry i : planeHash.entrySet()) {
- // for (Flights f : flightlist) {
- //
- // String key = (String)i.getKey();
- // String value = (String)i.getValue();
- // String dep = f.departure;
- // String des = f.destination;
- // System.out.println(key + " (" + value + " ppl)" + " (" + dep + "-" + des + ")");
- // }
- // }
- }
- public void printPlaneInfo() {
- System.out.println("Give plane ID: ");
- String search = reader.nextLine();
- if (planeHash.containsKey(search)) {
- System.out.println(search + " (" + planeHash.get(search) + " ppl)");
- }
- }
- public void options() {
- System.out.println("Choose operation:\n" + "[1] Print planes\n" + "[2] Print flights\n" +
- "[3] Print plane info\n" + "[x] Quit");
- }
- }
- public class Flights {
- public String id;
- public String departure;
- public String destination;
- public Flights(String id, String dep, String des) {
- this.id = id;
- this.departure = dep;
- this.destination = des;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement