Question
Keep in mind:
1. That you should try to group passengers together if they are travelling together
2. If they do not choose specific seats, then choose by preferences
3. You may also want to have a method for placing passengers in the next available spot, if there are no preferences
4. You should display the current availability of the seats (O for Empty, X for occupied)
5. Break down the program into methods as much as possible.
Also store specific details of each passenger, along with their seating chart.
The seating chart can look something like:
----------
/ \
// \\
| OOO OOO|
| OOO OOO| Section 1
| OOO OOO|
| OOO OOO|
| OOO OOO|
| OOO OOO|
| OOO OOO|
| |
| OOO OOO|
| OOO OOO|
| OOO OOO| Section 2
| OOO OOO|
| OOO OOO|
| |
| OOO OOO|
| OOO OOO|
| OOO OOO| Section 3
| OOO OOO|
| OOO OOO|
| OOO OOO|
Solution Preview
This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.
import java.util.Scanner;public class PlaneManager {
static class Passenger
{
int row, col;
String seatingPref;
char occupied;
public Passenger()
{
occupied = 'O';
}
}
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
Passenger[][] seats = new Passenger[18][6];
int passengers, choice;
for(int i = 0; i < seats.length; i++)
for(int j = 0; j < seats[i].length; j++)
seats[i][j] = new Passenger();
while(true)
{
displayPlane(seats);
System.out.println("Welcome to my airline, how many are flying today (0 to exit): ");
passengers = input.nextInt();
if(passengers == 0)
{
System.out.println("Exiting program, goodbye");
break;
}
for(int i = 0; i < passengers; i++)
{
System.out.println("Passenger " + (i+1) + ": Here are some options:");
System.out.println("1. Choose a specific seat");
System.out.println("2. Give a preference");
System.out.println("3. No preference");
System.out.print("Choice: ");
choice = input.nextInt();
if(choice == 1){
if(!specificSeat(seats, input))
i = i-1;
}
else if(choice == 2){
if(!preferredSeat(seats, input))
i = i -1;
}
else if(choice == 3){
if(!noPreference(seats))
i = i-1;
}
else
{
System.out.println("Not a choice, going back to menu");
i= i-1;
continue;
}
}
}
}...