|
1 | 1 | import java.io.IOException;
|
| 2 | +import java.util.Arrays; |
| 3 | +import java.util.Collections; |
2 | 4 | import java.util.Scanner;
|
| 5 | +import java.util.ArrayList; |
3 | 6 |
|
4 | 7 |
|
5 | 8 | public class PassengerMenus {
|
6 | 9 |
|
7 | 10 | /**
|
8 | 11 | * @param args
|
| 12 | + * @return |
9 | 13 | * @throws IOException
|
10 | 14 | */
|
11 | 15 | public static void main(String[] args) throws IOException {
|
12 |
| - Scanner input = new Scanner(System.in); |
| 16 | + boolean run = true; |
| 17 | + while (run){ |
| 18 | + Scanner input = new Scanner(System.in); |
13 | 19 | System.out.println("============ Menu 1 ============");
|
14 | 20 | System.out.print("Enter option(1, 2, 3): ");
|
15 | 21 | String option = input.nextLine();
|
16 |
| - |
| 22 | + Integer option1 = Integer.valueOf(option); |
| 23 | + if(option1 == 3){ |
| 24 | + System.exit(0); |
| 25 | + } |
17 | 26 |
|
18 | 27 | System.out.print("Enter your first name: ");
|
19 | 28 | String first = input.nextLine();
|
20 | 29 |
|
21 | 30 |
|
22 | 31 | System.out.print("Enter your last name: ");
|
23 | 32 | String last = input.nextLine();
|
| 33 | + if(option1 == 1){ |
24 | 34 | System.out.println("newPassenger: " + first + " "+ last);
|
25 |
| - |
| 35 | + } |
| 36 | + if(option1 == 2){ |
| 37 | + System.out.println("findPassenger: " + first + " "+ last); |
| 38 | + } |
26 | 39 |
|
27 | 40 | System.out.println("============ Menu 2 ============");
|
28 | 41 | System.out.print("Enter option(1, 2, 3, 4): ");
|
29 | 42 | String option2 = input.nextLine();
|
| 43 | + int option3; |
| 44 | + option3 = Integer.valueOf(option2); |
| 45 | + |
30 | 46 |
|
| 47 | + if (option3 == 1){ |
31 | 48 | System.out.print("Enter <Originating airport> (three letter code): ");
|
32 | 49 | String origin = input.nextLine();
|
33 | 50 |
|
34 | 51 | System.out.print("Enter <Destination airport> (three letter code): ");
|
35 | 52 | String destin = input.nextLine();
|
36 |
| - |
| 53 | + |
37 | 54 | System.out.println("findAvalibleFlig1htPlans: " + origin + " "+ destin);
|
| 55 | + break; |
| 56 | + } |
| 57 | + |
| 58 | + if (option3 ==4){ |
| 59 | + run=true; |
| 60 | + } |
| 61 | + if (option3 ==2){ |
| 62 | + get(); |
38 | 63 |
|
39 |
| - } |
40 |
| -} |
| 64 | + break; |
| 65 | + } |
| 66 | + if (option3 ==3){ |
| 67 | + |
| 68 | + break; |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + |
| 73 | + |
| 74 | + } |
| 75 | + |
| 76 | + private static String[] codes = {"GNV", "BTR", "MCO", "MIA", "ATL", "IAH", "LAX", "JFK", "LGA", "ORD", "BOS", "ANC", "DEN", "SLC", "SFO", "IAD", "SEA", "OKC"}; |
| 77 | + |
| 78 | + // Used internally. |
| 79 | + private static int getRandomInt(int min, int max) |
| 80 | + { |
| 81 | + int x; // We're going to divide integers. |
| 82 | + // Don't allow y == 0! |
| 83 | + |
| 84 | + x = (int) (Math.random() * (max - min) + min); |
| 85 | + |
| 86 | + return x; |
| 87 | + } |
| 88 | + |
| 89 | + /** |
| 90 | + * Gets a randomly-generated itinerary - a array of sequential airport code pairings. |
| 91 | + * @return |
| 92 | + */ |
| 93 | + public static String[] get() |
| 94 | + { |
| 95 | + ArrayList<String> codeList = new ArrayList<String>(Arrays.asList(codes)); |
| 96 | + |
| 97 | + Collections.shuffle(codeList); |
| 98 | + |
| 99 | + int count = getRandomInt(1, 6); |
| 100 | + |
| 101 | + String[] itinerary = new String[count]; |
| 102 | + |
| 103 | + for(int i=0; i < count; i++) |
| 104 | + { |
| 105 | + itinerary[i] = codeList.get(i) + "-" + codeList.get(i+1); |
| 106 | + } |
| 107 | + |
| 108 | + return itinerary; |
| 109 | + } |
| 110 | + |
| 111 | + } |
| 112 | + |
| 113 | + |
41 | 114 |
|
0 commit comments