Skip to content

Commit 771aeb3

Browse files
committed
Menus: Added more options and started the second menu
1 parent 7ac2d17 commit 771aeb3

File tree

2 files changed

+120
-6
lines changed

2 files changed

+120
-6
lines changed

PassengerMenus.java

Lines changed: 79 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,114 @@
11
import java.io.IOException;
2+
import java.util.Arrays;
3+
import java.util.Collections;
24
import java.util.Scanner;
5+
import java.util.ArrayList;
36

47

58
public class PassengerMenus {
69

710
/**
811
* @param args
12+
* @return
913
* @throws IOException
1014
*/
1115
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);
1319
System.out.println("============ Menu 1 ============");
1420
System.out.print("Enter option(1, 2, 3): ");
1521
String option = input.nextLine();
16-
22+
Integer option1 = Integer.valueOf(option);
23+
if(option1 == 3){
24+
System.exit(0);
25+
}
1726

1827
System.out.print("Enter your first name: ");
1928
String first = input.nextLine();
2029

2130

2231
System.out.print("Enter your last name: ");
2332
String last = input.nextLine();
33+
if(option1 == 1){
2434
System.out.println("newPassenger: " + first + " "+ last);
25-
35+
}
36+
if(option1 == 2){
37+
System.out.println("findPassenger: " + first + " "+ last);
38+
}
2639

2740
System.out.println("============ Menu 2 ============");
2841
System.out.print("Enter option(1, 2, 3, 4): ");
2942
String option2 = input.nextLine();
43+
int option3;
44+
option3 = Integer.valueOf(option2);
45+
3046

47+
if (option3 == 1){
3148
System.out.print("Enter <Originating airport> (three letter code): ");
3249
String origin = input.nextLine();
3350

3451
System.out.print("Enter <Destination airport> (three letter code): ");
3552
String destin = input.nextLine();
36-
53+
3754
System.out.println("findAvalibleFlig1htPlans: " + origin + " "+ destin);
55+
break;
56+
}
57+
58+
if (option3 ==4){
59+
run=true;
60+
}
61+
if (option3 ==2){
62+
get();
3863

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+
41114

PassengerMenus.java~

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import java.io.IOException;
2+
import java.util.Scanner;
3+
4+
5+
public class PassengerMenus {
6+
7+
/**
8+
* @param args
9+
* @throws IOException
10+
*/
11+
public static void main(String[] args) throws IOException {
12+
Scanner input = new Scanner(System.in);
13+
System.out.println("============ Menu 1 ============");
14+
System.out.print("Enter option(1, 2, 3): ");
15+
String option = input.nextLine();
16+
17+
18+
System.out.print("Enter your first name: ");
19+
String first = input.nextLine();
20+
21+
22+
System.out.print("Enter your last name: ");
23+
String last = input.nextLine();
24+
System.out.println("newPassenger: " + first + " "+ last);
25+
26+
27+
System.out.println("============ Menu 2 ============");
28+
System.out.print("Enter option(1, 2, 3, 4): ");
29+
String option2 = input.nextLine();
30+
31+
System.out.print("Enter <Originating airport> (three letter code): ");
32+
String origin = input.nextLine();
33+
34+
System.out.print("Enter <Destination airport> (three letter code): ");
35+
String destin = input.nextLine();
36+
37+
System.out.println("findAvalibleFlig1htPlans: " + origin + " "+ destin);
38+
39+
}
40+
}
41+

0 commit comments

Comments
 (0)