An aircraft has 200 seats each row has 4 seats with an isle
Solution
import java.util.Scanner;
// Need for the Scanner class.
public class Seating
{
// Fields.
// Create an 2D array that has 15 rows and 6 colums.
private char[][] seats;
private static String lastName; // To hold the last Name.
private static final char EMPTY_SEAT = \'X\';
private static final char FILLED_SEAT = \'O\';
// Create a instance of the CustomerName class.
CustomerName ln = new CustomerName(lastName);
// Create a instance of the TicketType class.
//TicketType tty = new TicketType(FirstClass, EconomyClass);
//The displaySeats method shows the seats to the user.
public static void displaySeats ( char [][] seats )
{
// Populate the 2-dimensional array
/* for ( int r = 0; r < seats.length; r++ )
{
for ( int c = 0; c < seats[r].length ; c++ )
{
seats [r] [c] = EMPTY_SEAT;
} // End of inner for loop
} // End of outer for loop
*/
//This nested for loop displays the seats on the airplane.
System.out.println ( \" S E A T S\ \" );
System.out.println(\"\\t A B C D E F \ \");
for ( int r = 0; r < seats.length; r++ )
{
if ( (r+1) < 10 )
System.out.print ( \"Row Number: \"+ (r+1) + \" \" );
else
System.out.print ( \"Row Number: \"+ (r+1) + \" \" );
for ( int c = 0; c < seats[r].length; c++ )
{
System.out.print ( seats[r] [c] + \" \" );
} // End of inner for loop
System.out.println ();
} // End of outer for loop
System.out.print(\"\ \");
System.out.println(\"Rows 1,2 and 3 are first class; \" +
\" the remaining rows are economy class.\");
System.out.print(\"Rows 1 through 9 are interent ready.\ \");
System.out.print(\"\ \");
} // End of the displaySeats method.
/*
The displayMenu method shows the opinions that a user can chose
from.
*/
public static void displayMenu()
{
System.out.println ( \"Choose one of the following opinions:\" );
System.out.println ( \"1 Book a seat\" );
System.out.println ( \"2 Cancel a booking\" );
System.out.println ( \"3 Write human-readable output file\" );
System.out.println ( \"4 Write machine-readable output file\" );
System.out.println ( \"5 Exit program\ \" );
System.out.println ();
} // End of the displayMenu method
//=============================================
// The getMenuResponse method returns what the user chose.
public static char getMenuResponse ()
{
// Create a Scanner object for keyboard input.
Scanner keyboard = new Scanner(System.in);
// Get the user\'s response to the menu
System.out.print ( \"Enter your choice: \" );
String s = keyboard.next();
char choice = s.charAt(0);
return choice;
} // End of the getMenuResponse method.
//===============================================
// The MenuResponse method takes what user choose.
public static void MenuResponse ( char response, char [][] seats ) //throws IOException
{
// Create a Scanner object for keyboard input.
Scanner keyboard = new Scanner(System.in);
switch (response)
{
case \'1\':
System.out.println(\"You want to book a seat.\");
// Ask the user to enter his/her last name.
System.out.println(\"Pleae enter your last name\");
lastName = keyboard.nextLine();
System.out.print(\"\ \");
break;
case \'2\':
System.out.println(\"You want to cancel a booking.\");
keyboard.nextLine();
break;
case \'3\':
System.out.println(\"You want to write a human-readable file.\");
break;
case \'4\':
System.out.println(\"You want to write a machine-readable file.\");
break;
case \'5\':
System.out.println(\"Exit program.\");
System.exit ( 1 );
break;
default:
System.out.println(\"Not an acceptable response !!!\");
}
} // End of the MenuResponse method.
//====================================================
/*
The displayTicketMenu method shows the opinions that a user
can choose from.
*/
//========================================================
public static void displayTicketMenu()
{
System.out.println ( \"Choose one of the following tickets:\" );
System.out.println ( \"1. First class\" );
System.out.println ( \"2. Economy class\" );
System.out.println ( \"3. Exit program\ \" );
System.out.println ();
} // End of the displayMenu method.
//================================================
// The getTicketResponse method returns what the user choose.
public static char getTicketResponse ()
{
// Create a Scanner object for keyboard input.
Scanner keyboard = new Scanner(System.in);
// Get the user\'s response to the menu
System.out.print ( \"Enter your choice: \" );
String s = keyboard.next();
char choice = s.charAt(0);
return choice;
} // End of the getTicketResponse method.
//=======================================================
// The ticketResponse method takes what user choose and excutes it.
public static void ticketResponse(char ticketType, char[][] seats)
{
String input; // To hold the input.
char choice; // To store the user\'s choice
// Create a Scanner object for keyboard input.
Scanner keyboard = new Scanner(System.in);
switch (ticketType)
{
case \'1\' :
System.out.println(\"You want a ticket in first class\");
if (ticketType == 1)
{
System.out.println(lastName);
}
break;
case \'2\':
System.out.println(\"You want a ticket in second class\");
System.out.println();
System.out.println(\"What section do you want to seat in\" +
\" 1. Interent\" +
\" 2. No-Interent\");
input = keyboard.nextLine();
choice = input.charAt(0); // Get the first char.
// Get what user choose and excute it.
switch (choice)
{
case \'1\':
System.out.println(\"Interent section\");
break;
case \'2\':
System.out.println(\"No-Interent section\");
break;
default:
System.out.println(\"Not an acceptable response !!!\");
}
break;
case \'3\':
System.out.println(\"Exit program\ \");
System.exit ( 1 );
default:
System.out.println(\"Not an acceptable response !!!\");
} // End of the switch.
} // End of the ticketResponse method.
//======================================================
// The isFirstClassfull method check to see if there is a empty seat.
public static boolean isFirstClassfull(char[][] seats)
{
boolean answer = true; // Flag.
for (int row = 0; row < 3; row++ )
{
for (int col = 0; col < seats[0].length; col++ )
if (seats[row][col] == EMPTY_SEAT)
answer = false;
}
return answer;
}
}






