Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Write a class that can be used to assign seats for a commercial airplane. The airplane has 13 rows, with 6 seats in each row.

Write a class that can be used to assign seats for a commercial airplane. The airplane has

13 rows, with 6 seats in each row. Row 1 and 2 are first class; the remaining rows are

economy class. Also, rows 1 through 7 are nonsmoking. Your program must prompt the

user to enter the following information:

a. Ticket type (first class or economy class)

b. For economy class, the smoking or nonsmoking section

c. Desired seat (example: 7F)

Output the seating assignment in the following form:

A

B

C

D

E

F

Row 1 * * X * X X

Row 2 * X * X * X

Row 3 * * X X * X

Row 4 X * X * X X

Row 5 * X * X * *

Row 6 * X * * * X

Row 7 X * * * X X

Row 8 * X * X X *

Row 9 X * X X * X

Row 10 * X * X X X

Row 11 * * X * X *

Row 12 * * X X * X

Row 13 * * * * X *

Here, * indicates that the seat is available; X indicates that the seat is occupied. Make this

a menu-driven program; show the users choices and allow the user to make the

appropriate choices.

1. Import the template provided below:

/**

* This is airplane seats assigning program.

*

* @author (Chris Lululala)

* @version

* @since

*

*/

import java.util.*;

public class ASA

{

//attributes

//constructors

/**

* Constructor for objects of class ASA

* declare and initialize the local variables.

* Initialize the seats array with '*' character.

* Until a user choose to stop the program, repeat the program.

* First display the current seat assignment map.

* Display the menus and instructions, then a user choose one

* from the menu then type in required seat number. Next assign

* the user to the user's requested seat. Then report the result.

*/

public ASA()

{

// declare and initialize the local variables

Scanner scnr = new Scanner(System.in);

int choice; //from the menu

char[][] seats = new char[13][6];

String seatNo = ""; //user input of the seat#

int row = 0; //user requested seat row index number for the seats array

int column = 0; //user requested seat column index number for the seats array

// initialize the seats array with '*' character.

// real seat assignment operation here.

}

//methods

/**

* printSeats method gets an array for seats

* then prints the current status of seats.

*

* @param seatStatus a parameter for the current seats array.

* @return no returns at all.

*/

public void printSeats(char [][] seatStatus)

{

}

/**

* printMenu method prints the menu of this program's operations.

*

* @param no parameter.

* @return no returns at all.

*/

public void printMenu()

{

}

/**

* First method gets an array for seats, and a seat number,

* then assign the requested seat. If already assigned by another user

* or requested wrong seats, prints a warning message.

*

* @param seatStatus a parameter for the current seats array.

* @param row row index number of seatStatus for the requested seat

* @param col column index number of seatStatus for the requested seat

* @return no returns at all.

*/

public void First(char [][] seatStatus, int row, int col)

{

}

/**

* EconomySmoking method gets an array for seats, and a seat number,

* then assign the requested seat. If already assigned by another user

* or requested wrong seats, prints a warning message.

*

* @param seatStatus a parameter for an seats array.

* @param row row number of the requested seat

* @param col column number of the requested seat

* @return no returns at all.

*/

public void EconomySmoking(char [][] seatStatus, int row, int col)

{

}

/**

* EconomyNonSmoking method gets an array for seats, and a seat number,

* then assign the requested seat. If already assigned by another user

* or requested wrong seats, prints a warning message.

*

* @param seatStatus a parameter for an seats array.

* @param row row number of the requested seat

* @param col column number of the requested seat

* @return no returns at all.

*/

public void EconomyNonSmoking(char [][] seatStatus, int row, int col)

{

}

}

2. Theres no attribute required this time.

3. Define the constructor.

a. ASA: Constructor for objects of class ASA declare and initialize the local

variables. Initialize the seats array with '*' character. Until a user choose

to stop the program, repeat the program. First display the current seat

assignment map. Display the menus and instructions, then a user choose

one from the menu then type in required seat number. Next assign the

user to the user's requested seat. Then report the result.

4. Define the methods as following:

a. printSeats method: This method gets one parameter of character array to

get the current seat assign status. Doesnt return at all. Must generate the

output like below:

A B C D E F

Row 1 * * * * * *

Row 2 * * * * * *

Row 3 * * * * * *

Row 4 * * * * * *

Row 5 * * * * * *

Row 6 * * * * * *

Row 7 * * * * * *

Row 8 * * * * * *

Row 9 * * * * * *

Row 10 * * * * * *

Row 11 * * * * * *

Row 12 * * * * * *

Row 13 * * * * * *

b. printMenu method: This method doesnt have any parameter and return.

Just print the menu of operations for airplane seat assignments. Must

generate the print-out like following:

MENU=======================================

1. First Class

2. Economy Class - Smoking

3. Economy Class - Non Smoking

4. Quit this program

===========================================

Enter your choice (1,2,3, or 4):

c. First: This method assigns the first class seats. It needs 3 parameters. The

character array parameter seatStatus is to get the current seat assignment

status. Row and col parameters are to get row and column numbers of the

requested seat. Successfully assigned or not, the result report must be

displayed to the monitor. The examples of the result report are as

following:

MENU=======================================

1. First Class

2. Economy Class - Smoking

3. Economy Class - Non Smoking

4. Quit this program

===========================================

Enter your choice (1,2,3, or 4):

1

Enter the seat number you want:

1a

Your requested seat(1A) is reserved for you.

A B C D E F

Row 1 X * * * * *

Row 2 * * * * * *

Row 3 * * * * * *

Row 4 * * * * * *

Row 5 * * * * * *

Row 6 * * * * * *

Row 7 * * * * * *

Row 8 * * * * * *

Row 9 * * * * * *

Row 10 * * * * * *

Row 11 * * * * * *

Row 12 * * * * * *

Row 13 * * * * * *

MENU=======================================

1. First Class

2. Economy Class - Smoking

3. Economy Class - Non Smoking

4. Quit this program

===========================================

Enter your choice (1,2,3, or 4):

1

Enter the seat number you want:

1a

Your requested seat has already assigned to another

customer.

MENU=======================================

1. First Class

2. Economy Class - Smoking

3. Economy Class - Non Smoking

4. Quit this program

===========================================

Enter your choice (1,2,3, or 4):

1

Enter the seat number you want:

4a

Your requested seat is not a first-class seat, try again.

This method dosent return.

d. EconomySmoking: This method assigns the smoking economy class seats.

It needs 3 parameters. The character array parameter seatStatus is to get

the current seat assignment status. Row and col parameters are to get row

and column numbers of the requested seat. Successfully assigned or not,

the result report must be displayed to the monitor. This method dosent

return.

e. EconomyNonSmoking: This method assigns the non-smoking economy

class seats. It needs 3 parameters. The character array parameter

seatStatus is to get the current seat assignment status. Row and col

parameters are to get row and column n

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

differentiate the function ( x + 1 ) / ( x ^ 3 + x - 6 )

Answered: 1 week ago