Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi I need help with a java program that I need to create a Airline Reservation S

ID: 3771173 • Letter: H

Question

Hi I need help with a java program that I need to create a Airline Reservation System I already finish it but it doesnt work can someone please help me I would be delighted it doesnt show the available seats when running the program and I need it to run until someone says no for booking a seat and if they want to cancel a seat it should ask the user to cancel a seat or continue booking also it should prompt them to go back to the main menu and choose a ticket type and a row number and column here is my program

import java.io.*;
import java.util.*;
public class AirReservations {

   static Scanner scan = new Scanner(System.in);

   public static void main(String[] args) {
       // TODO Auto-generated method stub

       {
           //creats new array, at this point all of the values are set to null
           char[][] seats = new char[13][6];

           MenuSystem myMenu = new MenuSystem();
           myMenu.presentMenu("main",0);
           myMenu.presentSeatingChoice("sc-menu",0);
           myMenu.presentClassChoice("cc-menu",0);
           myMenu.presentRowChoiceMenu("rc-menu",0);
           myMenu.presentColumnChoiceMenu("col-menu",0);

           SeatingSystem mySystem = new SeatingSystem();
           mySystem.displaySeatingchart(seats);
           mySystem.seatAvailable(seats, "seatCode");
           mySystem.seatAssign(seats, "seatCode");
           mySystem.seatUnAssign(seats, "seatCode");

           //this method will populate the array with "*" instead of nulls,
           //denoting an empty seat
           pupulateGrid(seats);

           //prompt user, 0 to quit 1 to reserve
           System.out.println("Enter 0 to quit or 1 to reserve a ticket");

           //choice is the result of the above prompt
           int choice = scan.nextInt();

           //if choice is 0 then the user does not run this loop and they are done
           //booking id choice is 1 the loop below will run.
           while(choice != 0)
           {

               //the rowMessage() asks the user for a row choice i.e. A, B, C, D, E
               //converts it to an int. We do this so we can use the numerical
               //value to index the array.

               int row = rowMessage();

               //the colMessage() asks the user for a numerical row choice
               //and returns and stores it into column
               int col = colMessage();

               //HERE IS WHERE WE CHECK IF THE ROW AND COL ENTERD IS VALID
               if(row<6&&col<13)
               {


                   // HERE IS WHERE WE CHECK IF THE seat is taken, if it is print seat taken
                   if (seats[row][col] == 'X')
                       System.out.println("seat taken");


                   //if the seat is empty mark it occupied using 'x'
                   if (seats[row][col] == '*')
                       seats[row][col] = 'x';

               }//END IF FOR VALID CHECK HERE


               System.out.print("Enter 0 to quit or 1 to reserve a ticket");
               choice = scan.nextInt();

           }

           printGrid(seats);
       }

   }

       public static int rowMessage()
       {
           System.out.println(" Enter your row as letter ");
           String rowLetter = scan.next();

           if( rowLetter.equals("A"))
               return 0;

           if( rowLetter.equals("B"))
               return 1;

           if( rowLetter.equals("C"))
               return 2;

           if( rowLetter.equals("D"))
               return 3;

           if( rowLetter.equals("E"))
               return 4;

           if( rowLetter.equals("F"))
               return 5;

           return 6;

       }

       public static int colMessage()
       {

           System.out.println(" Enter your column as letter ");
           int col = scan.nextInt();
           return col;
       }

       public static void printGrid(char[][] multiPassed)
       {
           for (int i = 0; i < 13; i++)
           {
               for (int j = 0; j < 6; j++)
               {
                   System.out.print(multiPassed[i][j]);

               }
               System.out.println("");
           }
       }

       public static void pupulateGrid(char[][] multiPassed)
       {
           for (int i = 0; i < 13; i++)
           {
               for (int j = 0; j < 6; j++)
               {
                   multiPassed[i][j] = '*';

               }
           }
       }
   }

import java.util.Scanner;


public class MenuSystem {
   //This will print the menuId which what the user want to do for the first
       //MainMenu
   public static int presentMenu(String menuId,int main)
   { Scanner scan = new Scanner(System.in);
       if(menuId.equals("main"))//This will equal the main menu of the Airline Reservation System
       {
   System.out.println("1. Book a reservation ");
   System.out.println("2. Cancel a reservation ");
   System.out.println("3. Print Current Seating Chart ");
   System.out.println("Press 0 to Exit System " );
   System.out.println("Please choose an option to proceed|| Pres '0' to exit to main menu ");
   menuId = scan.nextLine();
         
   int Menu=main;
       }
   return main;//This will return the main menu
   }
     
   //This will let the user to pick a choice either a ticket type or return
   //to the main menu
   public static int presentSeatingChoice(String menuId, int scChoicemenu)
   {
   Scanner scan = new Scanner(System.in);

   if (menuId.equals("sc-menu"))//This method will be be determined what the
                                   //user will want to do.
   {
   System.out.println("Seating Choice Menu");


   System.out.println("1) Choose Ticket Type (First Class, Business Class, Economy Class)");


   System.out.println("2) Exit to Main Menu");

   System.out.println("Pick a choice to proceed to the next section or type a to '2' to go back to the MainMenu");
   scChoicemenu = scan.nextInt();
   }

   int sChoice = scChoicemenu;
   return sChoice;//This will return the Seating Choice Menu
  
   }
     
   //This method will return the class choice menu
   public static int presentClassChoice(String menuId, int ccChoicemenu)
   {
   Scanner scan = new Scanner(System.in);

   if (menuId.equals("cc-menu"))// This will also equal to the menuId for
                                   // the class choice menu to appear
   {
   System.out.println("Class Choice Menu");
     
   System.out.println("1. Firstclass");
   System.out.println("2. Businessclass");
   System.out.println("3. Economyclass");
   System.out.println("0. Exit to the MainMenu");
   System.out.println("Please choose a Class choice or type '0'to return to return to the main menu");
   ccChoicemenu = scan.nextInt();
   }
   int cChoice = ccChoicemenu;
  
   return cChoice;// This will return the Class Choice Menu
   }
       //This method will let the user to choose what row they like to seat in
   public static int presentRowChoiceMenu(String menuId, int rwChoicemenu)   
   {
   Scanner scan = new Scanner(System.in);
   if(menuId.equals("rc-menu"));//Row Choice Menu inside a if statement that
                                   //Will equals to the choices below

   System.out.println("Row Choice Menu");

   System.out.println("1)(For first class type numbers type '1-2'");

   System.out.println("2)(For Business class type '3-7'");

   System.out.println("3)(For Economy class type '8-13' ");
   System.out.println("Choose a option to proceed to the column choice");
   rwChoicemenu= scan.nextInt();
     

   int rwChoice= rwChoicemenu;

   return rwChoice;
   }
  
   //This method is where the column choices will take place to let the user
   //Decide what column they like to place in
   public static int presentColumnChoiceMenu(String menuId, int cwChoice)
   {
   Scanner scan = new Scanner(System.in);
   System.out.println("Seat Choice Menu");

   if(menuId.equals("col-menu"));//Column Choice Menu will also be equal to the
                               //choices below
   {
   System.out.println("Pick a letter which you want to reserve in 'A=1' , 'B=2', 'C=3', 'D=4', 'E=5', 'F=6' ");
  
   System.out.println("Choose a option to proceed || Pres '0' to exit to main menu ");
   cwChoice = scan.nextInt();
   }
   int cChoice=cwChoice;

   return cwChoice;

   }
   }


public class SeatingSystem {
   public static final int ROWS = 13;
   public static final int COLS = 6;
   public static final void seat(char[][] seatingChart) {
   for(int i=0; i    for(int j=0;j    seatingChart[i][j] = '*';
   }
   }
   }//this is where the seatingSystem will determine if the seat is Available or not

   public static boolean seatAvailable(char [][] seatingChart, String seatCode)
   {   
   int row = 1, index = 1, col = 1;
   while(seatCode.charAt(index) >= '0' && seatCode.charAt(index) <= '9') {
   row = row*10 + (int)seatCode.charAt(index) - 48;
   index++;
   }
   col = (int)index - (int)'A';
   if(seatingChart[row][col] == '*')
   return true;
   else return false;
   }

   // This method will be an integer and a char statement with a nested
   //if else statment to assign the seat
   public static int seatAssign(char [][] seatingChart, String seatCode)
   {
   int row = 0, index = 0, col = 0;
   while(seatCode.charAt(index) >= '0' && seatCode.charAt(index) <= '9') {
   row = row*10 + (int)seatCode.charAt(index) - 48;
   index++;
   }
   col = (int)index - (int)'A';
   if(seatingChart[row][col] == '*') {
   seatingChart[row][col] = 'X';
   return 1;
   }
   return 0;
   }
   public static int seatUnAssign(char[][] seatingChart, String seatCode)
   {
   int row = 0, index = 0, col = 0;
   while(seatCode.charAt(index) >= '0' && seatCode.charAt(index) <= '9') {
   row = row*10 + (int)seatCode.charAt(index) - 48;
   index++;
   }
   col = (int)index - (int)'A';
   if(seatingChart[row][col] == 'X') {
   seatingChart[row][col] = '*';
   return 1;
   }
   return 0;
   }
     
   // this method will display and print the seating chart
   public static void displaySeatingchart(char[][]seatingChart)
   {
   System.out.print(" ");
   for(int j=0; j    System.out.print( (char)((int)'A' + j) + " ");
   }
   System.out.println();
   for(int i=0; i    System.out.print("Row" + String.valueOf(i+1) + " ");
   for(int j=0; j    System.out.print(seatingChart[i][j] + " ");
   }
   System.out.println();
   }
   }
   }

Explanation / Answer

//Air Reservations :

package com.test.java;

import java.util.Scanner;

public class AirReservations {
   static Scanner scan = new Scanner(System.in);

   public static void main(String[] args) {
       // TODO Auto-generated method stub
       {
           // creats new array, at this point all of the values are set to null
           char[][] seats = new char[13][6];
           choiceSelection(seats);
           // this method will populate the array with "*" instead of nulls,
           // denoting an empty seat
           pupulateGrid(seats);
           // prompt user, 0 to quit 1 to reserve
           choiceMenu(seats);
           printGrid(seats);
       }
   }

   private static void choiceSelection(char[][] seats) {
       int choice = menuSystemCall();
       System.out.println("Choice Choosen--->"+choice);
       switch (choice) {
       case 0:
           System.exit(0);

           break;
       case 1:
           seatingSystemCall(seats, choice);
           break;
       case 2:
           choice = menuSystemCall();
           seatingSystemCall(seats, choice);
           break;
       case 3:
           seatingSystemCall(seats, choice);
           break;
       default:
           choice = menuSystemCall();
           break;
       }
   }

   private static void choiceMenu(char[][] seats) {
       System.out.println("Enter 0 to quit or 1 to reserve a ticket");
       // choice is the result of the above prompt
       int choice = scan.nextInt();
       // if choice is 0 then the user does not run this loop and they are done
       // booking id choice is 1 the loop below will run.
       while (choice != 0) {
           // the rowMessage() asks the user for a row choice i.e. A, B, C, D,
           // E
           // converts it to an int. We do this so we can use the numerical
           // value to index the array.
           int row = rowMessage();
           // the colMessage() asks the user for a numerical row choice
           // and returns and stores it into column
           int col = colMessage();
           // HERE IS WHERE WE CHECK IF THE ROW AND COL ENTERD IS VALID
           if (row < 13 && col < 6) {
               // System.out.println("Seat Status--->"+seats[row][col]);
               // HERE IS WHERE WE CHECK IF THE seat is taken, if it is print
               // seat taken
               if (seats[row][col] == 'X')
                   System.out.println("seat taken by others already");

               // if the seat is empty mark it occupied using 'x'
               if (seats[row][col] == '*')
                   System.out.println("seat reserved for you");
               seats[row][col] = 'x';
           }// END IF FOR VALID CHECK HERE

           System.out.print("Enter 0 to quit or 1 to reserve a ticket");
           choice = scan.nextInt();
       }
   }

   private static void seatingSystemCall(char[][] seats, int ch) {
       SeatingSystem mySystem = new SeatingSystem();
       if (ch == 3 || ch == 1)
           mySystem.displaySeatingchart(seats);
       mySystem.seatAvailable(seats, "seatCode");
       mySystem.seatAssign(seats, "seatCode");
       if (ch == 2)
           mySystem.seatUnAssign(seats, "seatCode");
   }

   private static int menuSystemCall() {
       MenuSystem myMenu = new MenuSystem();
       int choice = myMenu.presentMenu("main");
       System.out.println("Choice menuSystemCall--->"+choice);
       if(choice == 0 || choice==2||choice==3){
           return choice;
       }
       myMenu.presentSeatingChoice("sc-menu", 0);
       myMenu.presentClassChoice("cc-menu", 0);
       myMenu.presentRowChoiceMenu("rc-menu", 0);
       myMenu.presentColumnChoiceMenu("col-menu", 0);
       return choice;
   }

   public static int rowMessage() {
       System.out.println(" Enter your row as letter ");
       String rowLetter = scan.next();
       if (rowLetter.equals("A"))
           return 0;
       if (rowLetter.equals("B"))
           return 1;
       if (rowLetter.equals("C"))
           return 2;
       if (rowLetter.equals("D"))
           return 3;
       if (rowLetter.equals("E"))
           return 4;
       if (rowLetter.equals("F"))
           return 5;
       if (rowLetter.equals("H"))
           return 6;
       if (rowLetter.equals("I"))
           return 7;
       if (rowLetter.equals("J"))
           return 8;
       if (rowLetter.equals("K"))
           return 9;
       if (rowLetter.equals("L"))
           return 10;
       if (rowLetter.equals("M"))
           return 11;
       if (rowLetter.equals("N"))
           return 12;

       return 12;
   }

   public static int colMessage() {
       System.out.println(" Enter your column number ");
       int col = scan.nextInt();
       return col;
   }

   public static void printGrid(char[][] multiPassed) {
       for (int i = 0; i < 13; i++) {
           for (int j = 0; j < 6; j++) {
               System.out.print(multiPassed[i][j]);
           }
           System.out.println("");
       }
   }

   public static void pupulateGrid(char[][] multiPassed) {
       for (int i = 0; i < 13; i++) {
           for (int j = 0; j < 6; j++) {
               multiPassed[i][j] = '*';
           }
       }
   }
}

//Menu system:

package com.test.java;

import java.util.Scanner;

public class MenuSystem {
   //This will print the menuId which what the user want to do for the first
//MainMenu
public static int presentMenu(String menuId)
{ Scanner scan = new Scanner(System.in);
if(menuId.equals("main"))//This will equal the main menu of the Airline Reservation System
{
System.out.println("1. Book a reservation ");
System.out.println("2. Cancel a reservation ");
System.out.println("3. Print Current Seating Chart ");
System.out.println("Press 0 to Exit System " );
System.out.println("Please choose an option to proceed|| Pres '0' to exit to main menu ");
menuId = scan.nextLine();
  
}
return Integer.parseInt(menuId);//This will return the main menu
}
  
//This will let the user to pick a choice either a ticket type or return
//to the main menu
public static int presentSeatingChoice(String menuId, int scChoicemenu)
{
Scanner scan = new Scanner(System.in);
if (menuId.equals("sc-menu"))//This method will be be determined what the
//user will want to do.
{
System.out.println("Seating Choice Menu");

System.out.println("1) Choose Ticket Type (First Class, Business Class, Economy Class)");

System.out.println("2) Exit to Main Menu");
System.out.println("Pick a choice to proceed to the next section or type a to '2' to go back to the MainMenu");
scChoicemenu = scan.nextInt();
}
int sChoice = scChoicemenu;
return sChoice;//This will return the Seating Choice Menu

}
  
//This method will return the class choice menu
public static int presentClassChoice(String menuId, int ccChoicemenu)
{
Scanner scan = new Scanner(System.in);
if (menuId.equals("cc-menu"))// This will also equal to the menuId for
// the class choice menu to appear
{
System.out.println("Class Choice Menu");
  
System.out.println("1. Firstclass");
System.out.println("2. Businessclass");
System.out.println("3. Economyclass");
System.out.println("0. Exit to the MainMenu");
System.out.println("Please choose a Class choice or type '0'to return to return to the main menu");
ccChoicemenu = scan.nextInt();
}
int cChoice = ccChoicemenu;

return cChoice;// This will return the Class Choice Menu
}
//This method will let the user to choose what row they like to seat in
public static int presentRowChoiceMenu(String menuId, int rwChoicemenu)   
{
Scanner scan = new Scanner(System.in);
if(menuId.equals("rc-menu"));//Row Choice Menu inside a if statement that
//Will equals to the choices below
System.out.println("Row Choice Menu");
System.out.println("1)(For first class type numbers type '1-2'");
System.out.println("2)(For Business class type '3-7'");
System.out.println("3)(For Economy class type '8-13' ");
System.out.println("Choose a option to proceed to the column choice");
rwChoicemenu= scan.nextInt();
  
int rwChoice= rwChoicemenu;
return rwChoice;
}

//This method is where the column choices will take place to let the user
//Decide what column they like to place in
public static int presentColumnChoiceMenu(String menuId, int cwChoice)
{
Scanner scan = new Scanner(System.in);
System.out.println("Seat Choice Menu");
if(menuId.equals("col-menu"));//Column Choice Menu will also be equal to the
//choices below
{
System.out.println("Pick a letter which you want to reserve in 'A=1' , 'B=2', 'C=3', 'D=4', 'E=5', 'F=6' ");

System.out.println("Choose a option to proceed || Pres '0' to exit to main menu ");
cwChoice = scan.nextInt();
}
int cChoice=cwChoice;
return cwChoice;
}
}

//Seating System:

package com.test.java;

public class SeatingSystem {
   public static final int ROWS = 13;
   public static final int COLS = 6;

   public static final void seat(char[][] seatingChart) {
       for (int i = 0; i < ROWS; i++) {
           for (int j = 0; j < COLS; j++) {
               seatingChart[i][j] = '*';
           }
       }
   }// this is where the seatingSystem will determine if the seat is Available
       // or not

   public static boolean seatAvailable(char[][] seatingChart, String seatCode) {
       int row = 1, index = 1, col = 1;
       while (seatCode.charAt(index) >= '0' && seatCode.charAt(index) <= '9') {
           row = row * 10 + (int) seatCode.charAt(index) - 48;
           index++;
       }
       if(index>(int) 'A')
       col = (int) index - (int) 'A';
       System.out.println(row +"--->"+col);
       if (seatingChart[row][col] == '*')
           return true;
       else
           return false;
   }

   // This method will be an integer and a char statement with a nested
   // if else statment to assign the seat
   public static int seatAssign(char[][] seatingChart, String seatCode) {
       int row = 0, index = 0, col = 0;
       while (seatCode.charAt(index) >= '0' && seatCode.charAt(index) <= '9') {
           row = row * 10 + (int) seatCode.charAt(index) - 48;
           index++;
       }
       if(index>(int) 'A')
       col = (int) index - (int) 'A';
       System.out.println("roiw"+row+"----->"+col);
       if (seatingChart[row][col] == '*') {
           seatingChart[row][col] = 'X';
           return 1;
       }
       return 0;
   }

   public static int seatUnAssign(char[][] seatingChart, String seatCode) {
       int row = 0, index = 0, col = 0;
       while (seatCode.charAt(index) >= '0' && seatCode.charAt(index) <= '9') {
           row = row * 10 + (int) seatCode.charAt(index) - 48;
           index++;
       }
       if(index>(int) 'A')
       col = (int) index - (int) 'A';
       if (seatingChart[row][col] == 'X') {
           seatingChart[row][col] = '*';
           return 1;
       }
       return 0;
   }

   // this method will display and print the seating chart
   public static void displaySeatingchart(char[][] seatingChart) {
       System.out.print(" ");
       for (int j = 0; j < COLS; j++) {
           System.out.print((char) ((int) 'A' + j) + " ");

       }
       System.out.println();
       for (int i = 0; i < ROWS; i++) {
           System.out.print("Row" + String.valueOf(i + 1) + " ");

           for (int j = 0; j < COLS; j++)
               System.out.print(seatingChart[i][j] + " ");
       }
       System.out.println();
   }
}