Commit c7360400 authored by User's avatar User

Finished

parent cf41296c
......@@ -77,71 +77,263 @@ public class reservation{
System.out.println("Input cannot be XX");//print out error message
continue;//skips loop
}
for(int s=0; s<6; s++) {
for(int s=0; s<6; s++) {//loop to search array
for(int r=0; r<3; r++) {
if(reserve.equals(plane[s][r])) {
System.out.println("Seat " + reserve + " has been booked for you");
plane[s][r] = "XX";
ticket(first,last,city,destination,section, reserve);
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 fucntion 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");
break;
default:
System.out.println("invalid input please choose Y or N");
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://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{
while(true){
System.out.println("There are no more seats, is it ok to be moved to another class?(Y/N)");
String choose = input.next();
switch(choose) {
case "N":
System.out.println("Sorry there is no available seat at the moment. The next flight is in 6 hours");
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
String choose = 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":
for(int s=6; s<15; s++) {
case "Y"://if the user types Y this code is run
for(int s=6; s<15; s++) {//loops through seats in business class
for(int r=0; r<3; r++) {
if(plane[s][r] != "XX") {
reserve = plane[s][r];
plane[s][r] = "XX";
section = "Business";
System.out.println("Your booked seat is " + reserve);
ticket(first,last,city,destination,section, reserve);
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(int s=15; s<30; s++) {
for(int s=15; s<30; s++) {//loops through seats in economy class
for(int r=0; r<3; r++) {
if(plane[s][r] != "XX") {
reserve = plane[s][r];
plane[s][r] = "XX";
section = "Economy";
System.out.println("Your booked seat is " + reserve);
ticket(first,last,city,destination,section, reserve);
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;
}
}
}
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;
default:
System.out.println("invalid input please choose Y or N");
break;
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 "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
break;
boolean seat1 = false;//boolean to check for available seats. Assumed that there are none
for(int p=6; p<15; p++) {//loop to go through seats in the business class rows
for(int q=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
String choose = 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(int s=6; s<15; s++) {//loop to go through the business class seats
for(int r=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(int s=6; s<15; s++) {//loop to search array
for(int r=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;
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
String choose = 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(int s=15; s<30; s++) {//loops through seats in economy class
for(int r=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(int s=0; s<6; s++) {//loops through seats in first class
for(int r=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
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
break;
boolean seat2 = false;//boolean to check for available seats. Assumed that there are none
for(int p=15; p<30; p++) {//loop to go through seats in the economy class rows
for(int q=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
String choose = 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(int s=15; s<30; s++) {//loop to go through the economy class seats
for(int r=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(int s=15; s<30; s++) {//loop to search array
for(int r=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;
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
String choose = 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(int s=6; s<15; s++) {//loops through seats in business class
for(int r=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(int s=0; s<6; s++) {//loops through seats in first class
for(int r=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
System.out.println("Invalid option. Please choose a number from 1 to 3\n------------");//prints out an error message
break;
......@@ -222,21 +414,19 @@ public class reservation{
System.out.print("\t");
}
}
public static void ticket(String first, String last, String city, String destination, String section, String reserve) {
System.out.println("Here are your ticket details:\n"
+ "\\n--------------------------"
public static void ticket(String first, String last, String city, String destination, String section, String reserve) {//define ticket printing function and receives passed data
System.out.println("Here are your ticket details:\n"//printing out ticket details/boarding pass
+ "\n--------------------------"
+ "\n\t|{BOARDING PASS}|"
+ "\n Name: " + first + " " + last
+ "\n From: " + city
+ "\n Name: " + first + " " + last//add names together
+ "\n From: " + city//add data to end of print lines
+ "\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 Section: " + section
+ "\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:-");
display(plane);
}
void main() {
display(plane);//display updated plane seat plan to the user
}
}
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