ticket(first,last,city,destination,section,reserve);//calls ticket fucntion and passes values over
return;
return;
}
}
}
}
}
}
System.out.println("Invalid input. Please choose an available seat. Seats with XX have been booked already and are not available");
System.out.println("Invalid input. Please choose an available seat. Seats with XX have been booked already and are not available");//print error message if corresponding seat number cannot be found
break;
default:
System.out.println("invalid input please choose Y or N");
break;
break;
default://outcome if above cases are not met
System.out.println("invalid input please choose Y or N");//print error message
break;//break out of loop
}
}
}
}
}
}
else{
else{//outcomes for no seats available
while(true){
while(true){//while loop to repeat code
System.out.println("There are no more seats, is it ok to be moved to another class?(Y/N)");
System.out.println("There are no more seats, is it ok to be moved to another class?(Y/N)");//asks user if they want to be moved
Stringchoose=input.next();
Stringchoose=input.next();//initialise variable choice and takes input
switch(choose){
switch(choose){//switch case for different input values
case"N":
case"N"://if the user types N this code is run
System.out.println("Sorry there is no available seat at the moment. The next flight is in 6 hours");
System.out.println("Sorry there is no available seat at the moment. The next flight is in 6 hours");//print out error message informing user of next flight
return;
return;
case"Y":
case"Y"://if the user types Y this code is run
for(ints=6;s<15;s++){
for(ints=6;s<15;s++){//loops through seats in business class
for(intr=0;r<3;r++){
for(intr=0;r<3;r++){
if(plane[s][r]!="XX"){
if(plane[s][r]!="XX"){//check to find a seat that isn't booked
reserve=plane[s][r];
reserve=plane[s][r];//set reserved seat to the unbooked seat
plane[s][r]="XX";
plane[s][r]="XX";//set array value to XX so cannot be double booked
section="Business";
section="Business";//changes their class to business since they have been moved
System.out.println("Your booked seat is "+reserve);
System.out.println("Your booked seat is "+reserve);//print out their booked seat
ticket(first,last,city,destination,section,reserve);//call function to print ticket and passes values over
return;
return;
}
}
}
}
}
}
System.out.println("Sorry there is no available seat in any class at the moment. The next flight is in 6 hours");
System.out.println("Sorry there is no available seat in any class at the moment. The next flight is in 6 hours");//print out error message if no seats in other classes
return;
return;
default:
default://code if above cases are not met
System.out.println("invalid input please choose Y or N");
System.out.println("invalid input please choose Y or N");//print error message
break;
break;//break and re-loops
}
}
}
}
}
}
case"2"://case if user chooses business class/2
case"2"://case if user chooses business class/2
section="Business class";//assigns the chosen class to the variable to be used later on
System.out.println("You have Chosen Business Class");//prints out the class that the user has chosen
System.out.println("You have Chosen Business Class");//prints out the class that the user has chosen
booleanseat1=false;//boolean to check for available seats. Assumed that there are none
for(intp=6;p<15;p++){//loop to go through seats in the business class rows
for(intq=0;q<3;q++){
if(plane[p][q]!="XX"){//checks if array value is NOT EQUAL to XX which means that there is a seat available
seat1=true;//value of the boolean is changed to signify presence of free seat
}
}
}
if(seat1==true){//if statement to run code if seat is available
while(true){//while loop to display options
System.out.println("Would you like to choose a seat?(Y/N)");//print out options
Stringchoose=input.next();//takes in the user input
switch(choose){//switch case for different outcomes
case"N"://if the user types N this code is run
System.out.println("Ok, You will be assigned the next available seat");//user informed that they are given the next available seat
for(ints=6;s<15;s++){//loop to go through the business class seats
for(intr=0;r<3;r++){
if(plane[s][r]!="XX"){//searches for the first seat that is NOT EQUAL to XX
reserve=plane[s][r];//sets the users' reserve seat to the array value
plane[s][r]="XX";//sets the seat to XX so that it can't be double booked
System.out.println("Your booked seat is "+reserve);//prints out booked seat
ticket(first,last,city,destination,section,reserve);//calls the ticket function to print out the ticket details
return;
}
}
}
return;
case"Y"://if the user types Y this code is run
System.out.println("Ok please choose a seat:"//asks user to choose their seat
+"\n Here is the plane seat layout");
display(plane);//calls display function to print out plane seat layout
System.out.println("\nSeat choice: ");
reserve=input.next();//grabs input from user
if(reserve.equals("XX")){//check for if the user types in XX
System.out.println("Input cannot be XX");//print out error message
continue;//skips loop
}
for(ints=6;s<15;s++){//loop to search array
for(intr=0;r<3;r++){
if(reserve.equals(plane[s][r])){//checks to see if user input is equal to array values
System.out.println("Seat "+reserve+" has been booked for you");//print out message to confirm booking
plane[s][r]="XX";//set array value to XX to prevent double booking
ticket(first,last,city,destination,section,reserve);//calls ticket function and passes values over
return;
}
}
}
System.out.println("Invalid input. Please choose an available seat. Seats with XX have been booked already and are not available");//print error message if corresponding seat number cannot be found
break;
break;
default://outcome if above cases are not met
System.out.println("invalid input please choose Y or N");//print error message
break;//break out of loop
}
}
}
else{//outcomes for no seats available
while(true){//while loop to repeat code
System.out.println("There are no more seats, is it ok to be moved to another class?(Y/N)");//asks user if they want to be moved
Stringchoose=input.next();//initialise variable choice and takes input
switch(choose){//switch case for different input values
case"N"://if the user types N this code is run
System.out.println("Sorry there is no available seat at the moment. The next flight is in 6 hours");//print out error message informing user of next flight
return;
case"Y"://if the user types Y this code is run
for(ints=15;s<30;s++){//loops through seats in economy class
for(intr=0;r<3;r++){
if(plane[s][r]!="XX"){//check to find a seat that isn't booked
reserve=plane[s][r];//set reserved seat to the unbooked seat
plane[s][r]="XX";//set array value to XX so cannot be double booked
section="Economy";//changes their class to economy since they have been moved
System.out.println("Your booked seat is "+reserve);//print out their booked seat
ticket(first,last,city,destination,section,reserve);//call function to print ticket and passes values over
return;
}
}
}
for(ints=0;s<6;s++){//loops through seats in first class
for(intr=0;r<3;r++){
if(plane[s][r]!="XX"){//check to find a seat that isn't booked
reserve=plane[s][r];//set reserved seat to the unbooked seat
plane[s][r]="XX";//set array value to XX so cannot be double booked
section="First";//changes their class to First since they have been moved
System.out.println("Your booked seat is "+reserve);//print out their booked seat
ticket(first,last,city,destination,section,reserve);//call function to print ticket and passes values over
return;
}
}
}
System.out.println("Sorry there is no available seat in any class at the moment. The next flight is in 6 hours");//print out error message if no seats in other classes
return;
default://code if above cases are not met
System.out.println("invalid input please choose Y or N");//print error message
break;//break and re-loops
}
}
}
case"3"://case if user chooses economy class/3
case"3"://case if user chooses economy class/3
section="Economy class";//assigns the chosen class to the variable to be used later on
System.out.println("You have Chosen Economy Class");//prints out the class that the user has chosen
System.out.println("You have Chosen Economy Class");//prints out the class that the user has chosen
booleanseat2=false;//boolean to check for available seats. Assumed that there are none
for(intp=15;p<30;p++){//loop to go through seats in the economy class rows
for(intq=0;q<3;q++){
if(plane[p][q]!="XX"){//checks if array value is NOT EQUAL to XX which means that there is a seat available
seat2=true;//value of the boolean is changed to signify presence of free seat
}
}
}
if(seat2==true){//if statement to run code if seat is available
while(true){//while loop to display options
System.out.println("Would you like to choose a seat?(Y/N)");//print out options
Stringchoose=input.next();//takes in the user input
switch(choose){//switch case for different outcomes
case"N"://if the user types N this code is run
System.out.println("Ok, You will be assigned the next available seat");//user informed that they are given the next available seat
for(ints=15;s<30;s++){//loop to go through the economy class seats
for(intr=0;r<3;r++){
if(plane[s][r]!="XX"){//searches for the first seat that is NOT EQUAL to XX
reserve=plane[s][r];//sets the users' reserve seat to the array value
plane[s][r]="XX";//sets the seat to XX so that it can't be double booked
System.out.println("Your booked seat is "+reserve);//prints out booked seat
ticket(first,last,city,destination,section,reserve);//calls the ticket function to print out the ticket details
return;
}
}
}
return;
case"Y"://if the user types Y this code is run
System.out.println("Ok please choose a seat:"//asks user to choose their seat
+"\n Here is the plane seat layout");
display(plane);//calls display function to print out plane seat layout
System.out.println("\nSeat choice: ");
reserve=input.next();//grabs input from user
if(reserve.equals("XX")){//check for if the user types in XX
System.out.println("Input cannot be XX");//print out error message
continue;//skips loop
}
for(ints=15;s<30;s++){//loop to search array
for(intr=0;r<3;r++){
if(reserve.equals(plane[s][r])){//checks to see if user input is equal to array values
System.out.println("Seat "+reserve+" has been booked for you");//print out message to confirm booking
plane[s][r]="XX";//set array value to XX to prevent double booking
ticket(first,last,city,destination,section,reserve);//calls ticket function and passes values over
return;
}
}
}
System.out.println("Invalid input. Please choose an available seat. Seats with XX have been booked already and are not available");//print error message if corresponding seat number cannot be found
break;
break;
default://outcome if above cases are not met
System.out.println("invalid input please choose Y or N");//print error message
break;//break out of loop
}
}
}
else{//outcomes for no seats available
while(true){//while loop to repeat code
System.out.println("There are no more seats, is it ok to be moved to another class?(Y/N)");//asks user if they want to be moved
Stringchoose=input.next();//initialise variable choice and takes input
switch(choose){//switch case for different input values
case"N"://if the user types N this code is run
System.out.println("Sorry there is no available seat at the moment. The next flight is in 6 hours");//print out error message informing user of next flight
return;
case"Y"://if the user types Y this code is run
for(ints=6;s<15;s++){//loops through seats in business class
for(intr=0;r<3;r++){
if(plane[s][r]!="XX"){//check to find a seat that isn't booked
reserve=plane[s][r];//set reserved seat to the unbooked seat
plane[s][r]="XX";//set array value to XX so cannot be double booked
section="Business";//changes their class to business since they have been moved
System.out.println("Your booked seat is "+reserve);//print out their booked seat
ticket(first,last,city,destination,section,reserve);//call function to print ticket and passes values over
return;
}
}
}
for(ints=0;s<6;s++){//loops through seats in first class
for(intr=0;r<3;r++){
if(plane[s][r]!="XX"){//check to find a seat that isn't booked
reserve=plane[s][r];//set reserved seat to the unbooked seat
plane[s][r]="XX";//set array value to XX so cannot be double booked
section="First";//changes their class to economy since they have been moved
System.out.println("Your booked seat is "+reserve);//print out their booked seat
ticket(first,last,city,destination,section,reserve);//call function to print ticket and passes values over
return;
}
}
}
System.out.println("Sorry there is no available seat in any class at the moment. The next flight is in 6 hours");//print out error message if no seats in other classes
return;
default://code if above cases are not met
System.out.println("invalid input please choose Y or N");//print error message
break;//break and re-loops
}
}
}
default://case if user chooses an invalid option
default://case if user chooses an invalid option
System.out.println("Invalid option. Please choose a number from 1 to 3\n------------");//prints out an error message
System.out.println("Invalid option. Please choose a number from 1 to 3\n------------");//prints out an error message
publicstaticvoidticket(Stringfirst,Stringlast,Stringcity,Stringdestination,Stringsection,Stringreserve){//define ticket printing function and receives passed data
System.out.println("Here are your ticket details:\n"
System.out.println("Here are your ticket details:\n"//printing out ticket details/boarding pass
+"\\n--------------------------"
+"\n--------------------------"
+"\n\t|{BOARDING PASS}|"
+"\n\t|{BOARDING PASS}|"
+"\n Name: "+first+" "+last
+"\n Name: "+first+" "+last//add names together
+"\n From: "+city
+"\n From: "+city//add data to end of print lines
+"\n To: "+destination
+"\n To: "+destination
+"\n Flight: FL"+randomflightnum(1,28)
+"\n Flight: FL"+randomflightnum(1,28)//call random flight generator number function, passes the min and max values the flight number values can be
+"\n Seat No.: "+reserve
+"\n Seat No.: "+reserve
+"\n Section: "+section
+"\n Section: "+section
+"\n--------------------------");
+"\n--------------------------");
System.out.println("Thanks for using our booking service"
System.out.println("Thanks for using our booking service"//print finishing message
+"\n Updated Plane seat plan:-");
+"\n Updated Plane seat plan:-");
display(plane);
display(plane);//display updated plane seat plan to the user