Commit f3174776 authored by Jordan's avatar Jordan

DONE

parent 4dc18bf8
......@@ -4,48 +4,85 @@ import java.util.Random;
public class AirlineReservation {
public static void main(String[] args) {
// Write an application to assign seats on each flight of the airplane.
// Each flight has 90 seats.
// Ask their name, origin city, destination city.
Scanner input1 = new Scanner(System.in);
String name, origin, destination;
System.out.println("Please enter your name: ");
name = input1.next();
System.out.println("Please enter your origin city: ");
origin = input1.next();
System.out.println("Please enter your destination city: ");
destination = input1.next();
// System then generates flight number, FL01 through FL28.
Random rand = new Random();
int flightno = rand.nextInt(29);
while (flightno==0) {
rand.nextInt(29);
}
System.out.println("Your flight number is: " + flightno);
String FirstClassSeats[][] = {{"01", "02", "03","04","05","06","07","08","09"},
{"10","11","12","13","14","15","16","17","18"}};
String BusinessClassSeats[][] = {{"19","20","21","22","23","24","25","26","27"},
{"28","29","30","31","32","33","34","35","36"},
{"37","38","39","40","41","42","43","44","45"}};
String EconomyClassSeats[][] = {{"46","47","48","49","50","51","52","53","54"},
{"55","56","57","58","59","60","61","62","63"},
{"64","65","66","67","68","69","70","71","72"},
{"73","74","75","76","77","78","79","80","81"},
{"82","83","84","85","86","87","88","89","90"}};
// this sets up the code to run indefinitely, so that the taken seats stay taken.
while (true) {
// This welcomes the user to the system, so when it loops it isn't confusing.
System.out.println("Hi, welcome to the boooking system!");
Scanner input1 = new Scanner(System.in);
// this sets up the strings that will be used later and allows the user to enter their detials
String name, origin, destination;
System.out.println("Please enter your name: ");
name = input1.next();
System.out.println("Please enter your origin city: ");
origin = input1.next();
System.out.println("Please enter your destination city: ");
destination = input1.next();
// this is a random number generator to generate the flight that the user will be getting on
Random rand = new Random();
int flightno = rand.nextInt(29);
while (flightno==0) {
rand.nextInt(29);
}
// One flight every six hours, 28 flights each week.
// Then display the following options
// this lets the user know what their flight number is
System.out.println("Your flight number is: " + flightno);
// this uses the methods from later to display the seating chart
System.out.println("First Class Seating");
System.out.println();
displayFCS(FirstClassSeats);
System.out.println();
System.out.println("Business Class Seating");
System.out.println();
displayBCS(BusinessClassSeats);
System.out.println();
System.out.println("Economy Class Seating");
System.out.println();
displayECS(EconomyClassSeats);
System.out.println();
System.out.println();
// this displays the next options for the user and tells them what it will do
System.out.println("Please type 1 for First Class");
System.out.println("Please type 2 for Business Class");
System.out.println("Please type 3 for Economy Class");
// Please type 1 for First Class
// Please type 2 for Business
// Please type 3 for Economy
// the following code sets up doubles for what the user chooses
double FirstClass, BusinessClass, EconomyClass;
// this assigns the value to each.
FirstClass = 1;
BusinessClass = 2;
EconomyClass = 3;
// the next thing the user inputs will correspond to the value of the class.
double FlightClass = input1.nextDouble();
//these let the user know which they've chosen, and thanks them
if (FlightClass == FirstClass) {
System.out.println("Thank you for choosing First Class.");
}
......@@ -63,75 +100,277 @@ public class AirlineReservation {
// Typing 2 gives the user a seat between 19-45
// Typing 3 gives the user a seat between 46-90
// The "if seatno == ??" code changes the corresponding spot in the arrays to an XX, to mark that it's taken.
int seatno = 0;
if (FlightClass == FirstClass) {
int seatno = rand.nextInt(18 - 1 + 1) + 1;
seatno = rand.nextInt(18 - 1 + 1) + 1;
System.out.println("Your seat number is: " + seatno);
if (seatno == 1)
FirstClassSeats[0][0] = "XX";
if (seatno == 2)
FirstClassSeats[0][1] = "XX";
if (seatno == 3)
FirstClassSeats[0][2] = "XX";
if (seatno == 4)
FirstClassSeats[0][3] = "XX";
if (seatno == 5)
FirstClassSeats[0][4] = "XX";
if (seatno == 6)
FirstClassSeats[0][5] = "XX";
if (seatno == 7)
FirstClassSeats[0][6] = "XX";
if (seatno == 8)
FirstClassSeats[0][7] = "XX";
if (seatno == 9)
FirstClassSeats[0][8] = "XX";
if (seatno == 10)
FirstClassSeats[1][0] = "XX";
if (seatno == 11)
FirstClassSeats[1][1] = "XX";
if (seatno == 12)
FirstClassSeats[1][2] = "XX";
if (seatno == 13)
FirstClassSeats[1][3] = "XX";
if (seatno == 14)
FirstClassSeats[1][4] = "XX";
if (seatno == 15)
FirstClassSeats[1][5] = "XX";
if (seatno == 16)
FirstClassSeats[1][6] = "XX";
if (seatno == 17)
FirstClassSeats[1][7] = "XX";
if (seatno == 18)
FirstClassSeats[1][8] = "XX";
}
if (FlightClass == BusinessClass) {
int seatno = rand.nextInt(45 - 19 + 1) + 19;
seatno = rand.nextInt(45 - 19 + 1) + 19;
System.out.println("Your seat number is: " + seatno);
if (seatno == 19)
BusinessClassSeats[0][0] = "XX";
if (seatno == 20)
BusinessClassSeats[0][1] = "XX";
if (seatno == 21)
BusinessClassSeats[0][2] = "XX";
if (seatno == 22)
BusinessClassSeats[0][3] = "XX";
if (seatno == 23)
BusinessClassSeats[0][4] = "XX";
if (seatno == 24)
BusinessClassSeats[0][5] = "XX";
if (seatno == 25)
BusinessClassSeats[0][6] = "XX";
if (seatno == 26)
BusinessClassSeats[0][7] = "XX";
if (seatno == 27)
BusinessClassSeats[0][8] = "XX";
if (seatno == 28)
BusinessClassSeats[1][0] = "XX";
if (seatno == 29)
BusinessClassSeats[1][1] = "XX";
if (seatno == 30)
BusinessClassSeats[1][2] = "XX";
if (seatno == 31)
BusinessClassSeats[1][3] = "XX";
if (seatno == 32)
BusinessClassSeats[1][4] = "XX";
if (seatno == 33)
BusinessClassSeats[1][5] = "XX";
if (seatno == 34)
BusinessClassSeats[1][6] = "XX";
if (seatno == 35)
BusinessClassSeats[1][7] = "XX";
if (seatno == 36)
BusinessClassSeats[1][8] = "XX";
if (seatno == 37)
BusinessClassSeats[2][0] = "XX";
if (seatno == 38)
BusinessClassSeats[2][1] = "XX";
if (seatno == 39)
BusinessClassSeats[2][2] = "XX";
if (seatno == 40)
BusinessClassSeats[2][3] = "XX";
if (seatno == 41)
BusinessClassSeats[2][4] = "XX";
if (seatno == 42)
BusinessClassSeats[2][5] = "XX";
if (seatno == 43)
BusinessClassSeats[2][6] = "XX";
if (seatno == 44)
BusinessClassSeats[2][7] = "XX";
if (seatno == 45)
BusinessClassSeats[2][8] = "XX";
}
if (FlightClass == EconomyClass) {
int seatno = rand.nextInt(90 - 46 + 1) + 46;
seatno = rand.nextInt(90 - 46 + 1) + 46;
System.out.println("Your seat number is: " + seatno);
if (seatno == 46)
EconomyClassSeats[0][0] = "XX";
if (seatno == 47)
EconomyClassSeats[0][1] = "XX";
if (seatno == 48)
EconomyClassSeats[0][2] = "XX";
if (seatno == 49)
EconomyClassSeats[0][3] = "XX";
if (seatno == 50)
EconomyClassSeats[0][4] = "XX";
if (seatno == 51)
EconomyClassSeats[0][5] = "XX";
if (seatno == 52)
EconomyClassSeats[0][6] = "XX";
if (seatno == 53)
EconomyClassSeats[0][7] = "XX";
if (seatno == 54)
EconomyClassSeats[0][8] = "XX";
if (seatno == 55)
EconomyClassSeats[1][0] = "XX";
if (seatno == 56)
EconomyClassSeats[1][1] = "XX";
if (seatno == 57)
EconomyClassSeats[1][2] = "XX";
if (seatno == 58)
EconomyClassSeats[1][3] = "XX";
if (seatno == 59)
EconomyClassSeats[1][4] = "XX";
if (seatno == 60)
EconomyClassSeats[1][5] = "XX";
if (seatno == 61)
EconomyClassSeats[1][6] = "XX";
if (seatno == 62)
EconomyClassSeats[1][7] = "XX";
if (seatno == 63)
EconomyClassSeats[1][8] = "XX";
if (seatno == 64)
EconomyClassSeats[2][0] = "XX";
if (seatno == 65)
EconomyClassSeats[2][1] = "XX";
if (seatno == 66)
EconomyClassSeats[2][2] = "XX";
if (seatno == 67)
EconomyClassSeats[2][3] = "XX";
if (seatno == 68)
EconomyClassSeats[2][4] = "XX";
if (seatno == 69)
EconomyClassSeats[2][5] = "XX";
if (seatno == 70)
EconomyClassSeats[2][6] = "XX";
if (seatno == 71)
EconomyClassSeats[2][7] = "XX";
if (seatno == 72)
EconomyClassSeats[2][8] = "XX";
if (seatno == 73)
EconomyClassSeats[3][0] = "XX";
if (seatno == 74)
EconomyClassSeats[3][1] = "XX";
if (seatno == 75)
EconomyClassSeats[3][2] = "XX";
if (seatno == 76)
EconomyClassSeats[3][3] = "XX";
if (seatno == 77)
EconomyClassSeats[3][4] = "XX";
if (seatno == 78)
EconomyClassSeats[3][5] = "XX";
if (seatno == 79)
EconomyClassSeats[3][6] = "XX";
if (seatno == 80)
EconomyClassSeats[3][7] = "XX";
if (seatno == 81)
EconomyClassSeats[3][8] = "XX";
if (seatno == 82)
EconomyClassSeats[4][0] = "XX";
if (seatno == 83)
EconomyClassSeats[4][1] = "XX";
if (seatno == 84)
EconomyClassSeats[4][2] = "XX";
if (seatno == 85)
EconomyClassSeats[4][3] = "XX";
if (seatno == 86)
EconomyClassSeats[4][4] = "XX";
if (seatno == 87)
EconomyClassSeats[4][5] = "XX";
if (seatno == 88)
EconomyClassSeats[4][6] = "XX";
if (seatno == 89)
EconomyClassSeats[4][7] = "XX";
if (seatno == 90)
EconomyClassSeats[4][8] = "XX";
}
// this code changes the doubles from earlier into strings with the corresponding flight class, to make it able to be put into the boarding pass
int[][] seats = new int[9][10];
int seatno=0;
for(int i=0; i<9; i++)
for(int j=0; j<10; j++) {
seats[i][j]=seatno;
seatno++;
if (seatno<=9) {
System.out.print("[" + 0 + seatno + "]" + " " + "" +" ");
}
else if (seatno<=18) {
System.out.print("[" + seatno + "]" + " ");
}
String FlightClass2 = Double.toString(FlightClass);
if (FlightClass == 1) {
FlightClass2 = "First Class";
}
if (FlightClass == 2) {
FlightClass2 = "Business Class";
}
if (FlightClass == 3) {
FlightClass2 = "Economy Class";
}
// This code prints out the boarding pass.
System.out.println();
System.out.println();
System.out.println("| BOARDING PASS |");
System.out.println("Name : " + name);
System.out.println("From : " + origin);
System.out.println("To : " + destination);
System.out.println("Flight : " + "FL" + flightno);
System.out.println("Seat No : " + seatno);
System.out.println("Section : " + FlightClass2);
System.out.println();
System.out.println();
// This code prints another seating chart
displayFCS(FirstClassSeats);
System.out.println();
displayBCS(BusinessClassSeats);
System.out.println();
displayECS(EconomyClassSeats);
System.out.println();
System.out.println();
System.out.println();
}
}
// this is the code that sets up the methods for displaying the seating chart.
static void displayFCS(String displayFCS[][]) {
for (int i=0; i<2; i++) {
for(int j=0; j<9; j++) {
System.out.print("[" + displayFCS[i][j] + "]" );
}
System.out.println();
}
}
static void displayBCS(String displayBCS[][]) {
for (int i=0; i<3; i++) {
for(int j=0; j<9; j++) {
System.out.print("[" + displayBCS[i][j] + "]" );
}
System.out.println();
}
// Display a seating chart using an array, using a 9x10 chart.
// After a seat is assigned, replace the seat number with XX in the array.
// [XX][XX][XX] [04][05][06] [07][08][09]
// [XX][XX][XX] [13][14][15] [16][17][18]
//
// [XX][XX][XX] [XX][XX][XX] [XX][XX][XX]
// [XX][XX][30] [31][32][33] [34][35][36]
// [XX][38][XX] [40][41][42] [43][44][45]
//
// [XX][XX][XX] [XX][XX][XX] [XX][XX][XX]
// [55][56][57] [58][59][60] [61][62][63]
// [XX][XX][XX] [67][68][69] [70][71][72]
// [XX][XX][XX] [XX][XX][XX] [XX][80][81]
// [82][83][XX] [85][86][XX] [88][89][90]
// XX means the seat is unavailable, do not assign another person there.
// When a section is completely full, ask the user if they would like to be placed in First/Business instead
// If yes, they are assigned a seat in one of the sections.
// If no, display this message:
// "Sorry, there is no available seating at the moment, next flight leaves in 6 hours."
// Print a boarding pass for them indicating name, origin city, destination city, flight number, seat number, and class.
// Print the seating array after.
}
}
static void displayECS(String displayECS[][]) {
for (int i=0; i<5; i++) {
for(int j=0; j<9; j++) {
System.out.print("[" + displayECS[i][j] + "]" );
}
System.out.println();
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment