Skip to content

Commit 9189123

Browse files
committed
Part 1: Menus and given random function
1 parent 1b3b758 commit 9189123

File tree

3 files changed

+123
-0
lines changed

3 files changed

+123
-0
lines changed

PassengerMenus

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+

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+

RandomItinerary.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import java.util.ArrayList;
2+
import java.util.Arrays;
3+
import java.util.Collections;
4+
5+
public class RandomItinerary
6+
{
7+
private static String[] codes = {"GNV", "BTR", "MCO", "MIA", "ATL", "IAH", "LAX", "JFK", "LGA", "ORD", "BOS", "ANC", "DEN", "SLC", "SFO", "IAD", "SEA", "OKC"};
8+
9+
// Used internally.
10+
private static int getRandomInt(int min, int max)
11+
{
12+
int x; // We're going to divide integers.
13+
// Don't allow y == 0!
14+
15+
x = (int) (Math.random() * (max - min) + min);
16+
17+
return x;
18+
}
19+
20+
/**
21+
* Gets a randomly-generated itinerary - a array of sequential airport code pairings.
22+
* @return
23+
*/
24+
public static String[] get()
25+
{
26+
ArrayList<String> codeList = new ArrayList<String>(Arrays.asList(codes));
27+
28+
Collections.shuffle(codeList);
29+
30+
int count = getRandomInt(1, 6);
31+
32+
String[] itinerary = new String[count];
33+
34+
for(int i=0; i < count; i++)
35+
{
36+
itinerary[i] = codeList.get(i) + "-" + codeList.get(i+1);
37+
}
38+
39+
return itinerary;
40+
}
41+
}

0 commit comments

Comments
 (0)