Arrays Change the program AirlineDriver.java to assign passenger seats in an airplane. Chesapeake Airlines is a small commuter airline with seats for 20 passengers in 5 rows of 4 seats each. Here is the layout: 1 ABCD 2 ABCD 3 ABCD 4 ABCD 5 ABCD The user enters the row (1-5) and the seat (A- D). The seat entry may be lowercase. Use this code to enter the seat System.out print(" Enter row and seat " seat scan.nextLine(): seat.?? C= seat.?? What will you need to do to change the character (A, B, C, D) in the variable c to the column index in the array? Check the program example on page 347. Ihave included the LetterCount program in the Chapter Seven Activities. The program checks the array to see if the seat is available. An X in the array indicates the seat is not available. If the seat is available, assign an X to that position in the array. If it's unavailable, display a message to the passenger. Use the displaySeats method after each row/seat entry. After some seats are assigned, the layout may look like this: 1 XBCX 2 ABCD 3 AXCX 4 ABCD 5 ABCD Continue processing requests until the user enters -1 for seat.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

using java

 Complete the attached assignment.

### Java Program to Display Airline Seat Layout

This Java program is designed to display the layout of seats in an airplane using a two-dimensional array. Below is the transcribed code and an explanation of its components.

```java
public class AirlineDriver {
    public static void main (String[] args) {
        char [][] layout = { {'A', 'B', 'C', 'D'},
                             {'A', 'B', 'C', 'D'},
                             {'A', 'B', 'C', 'D'},
                             {'A', 'B', 'C', 'D'},
                             {'A', 'B', 'C', 'D'}};

        displaySeats(layout);
    }

    public static void displaySeats(char [][] plane) {
        for (int row = 0; row < plane.length; row++) {
            System.out.print(" " + (row + 1) + " ");
            // Add for loop to display one row
            // Display row
            System.out.println();
        }
    }
}
```

### Explanation

1. **Class Declaration:**
   - `public class AirlineDriver`: This is the main class named `AirlineDriver`.

2. **Main Method:**
   - `public static void main (String[] args)`: This method is the entry point of any Java application. It initializes a two-dimensional char array named `layout` which represents the seat arrangement.

3. **Seat Layout Array:**
   - The `layout` array is a 5x4 grid, where each inner array represents a row of seats 'A', 'B', 'C', and 'D'.

4. **Display Function:**
   - `public static void displaySeats(char [][] plane)`: This method takes a 2D char array as an argument and prints the seat layout.
   - A `for` loop iterates over each row, printing the row number. The method suggests adding code inside the loop to display the actual seat characters.

5. **Potential Enhancements:**
   - Complete the inner loop to print each character in a row.
   - Format the output for better readability.

This code is a starting point for understanding how to handle 2D arrays in Java, particularly for applications such as managing seating arrangements in transportation systems.
Transcribed Image Text:### Java Program to Display Airline Seat Layout This Java program is designed to display the layout of seats in an airplane using a two-dimensional array. Below is the transcribed code and an explanation of its components. ```java public class AirlineDriver { public static void main (String[] args) { char [][] layout = { {'A', 'B', 'C', 'D'}, {'A', 'B', 'C', 'D'}, {'A', 'B', 'C', 'D'}, {'A', 'B', 'C', 'D'}, {'A', 'B', 'C', 'D'}}; displaySeats(layout); } public static void displaySeats(char [][] plane) { for (int row = 0; row < plane.length; row++) { System.out.print(" " + (row + 1) + " "); // Add for loop to display one row // Display row System.out.println(); } } } ``` ### Explanation 1. **Class Declaration:** - `public class AirlineDriver`: This is the main class named `AirlineDriver`. 2. **Main Method:** - `public static void main (String[] args)`: This method is the entry point of any Java application. It initializes a two-dimensional char array named `layout` which represents the seat arrangement. 3. **Seat Layout Array:** - The `layout` array is a 5x4 grid, where each inner array represents a row of seats 'A', 'B', 'C', and 'D'. 4. **Display Function:** - `public static void displaySeats(char [][] plane)`: This method takes a 2D char array as an argument and prints the seat layout. - A `for` loop iterates over each row, printing the row number. The method suggests adding code inside the loop to display the actual seat characters. 5. **Potential Enhancements:** - Complete the inner loop to print each character in a row. - Format the output for better readability. This code is a starting point for understanding how to handle 2D arrays in Java, particularly for applications such as managing seating arrangements in transportation systems.
**Educational Content: Assigning Passenger Seats in an Airplane**

**Arrays in Java Programming**

This exercise involves modifying the `AirlineDriver.java` program to assign passenger seats on a small commuter airline with a seating capacity of 20 passengers. The seating is organized into 5 rows of 4 seats each, as shown below:

```
1 A B C D
2 A B C D
3 A B C D
4 A B C D
5 A B C D
```

### User Input for Seat Selection

- **Instructions:** The user will input the seat selection by specifying the row number (1–5) and the seat letter (A–D). Note: The seat letter input can be in lowercase.

To capture the seat selection from the user, use the following code snippet:

```java
System.out.print("Enter row and seat ");
seat = scan.nextLine();

r = seat.??;  // Extract and assign row number
c = seat.??;  // Extract and assign seat letter
```

### Converting Seat Input to Array Indices

- **Objective:** Convert the seat letter (A, B, C, or D) into the corresponding column index in the array. Refer to the "LetterCount" program example in Chapter Seven Activities for guidance.

### Seat Assignment Logic

The program checks the availability of a seat by scanning the array. An 'X' in the array indicates the seat is not available.

- **Logic for Seat Availability:**
  - If the seat is available, assign 'X' at that position in the array.
  - If unavailable, notify the passenger and request a different selection using the `displaySeats` method after each entry.

### Example Layout After Seat Assignments

Once some seats have been assigned, the seating arrangement might resemble:

```
1 A B C X
2 A B C D
3 A B C X
4 A B C D
5 A B C D
```

**Note:** Continue processing seat requests until the user enters "1" for the seat.

This programming exercise helps reinforce understanding of arrays, user input handling, and control structures in Java.
Transcribed Image Text:**Educational Content: Assigning Passenger Seats in an Airplane** **Arrays in Java Programming** This exercise involves modifying the `AirlineDriver.java` program to assign passenger seats on a small commuter airline with a seating capacity of 20 passengers. The seating is organized into 5 rows of 4 seats each, as shown below: ``` 1 A B C D 2 A B C D 3 A B C D 4 A B C D 5 A B C D ``` ### User Input for Seat Selection - **Instructions:** The user will input the seat selection by specifying the row number (1–5) and the seat letter (A–D). Note: The seat letter input can be in lowercase. To capture the seat selection from the user, use the following code snippet: ```java System.out.print("Enter row and seat "); seat = scan.nextLine(); r = seat.??; // Extract and assign row number c = seat.??; // Extract and assign seat letter ``` ### Converting Seat Input to Array Indices - **Objective:** Convert the seat letter (A, B, C, or D) into the corresponding column index in the array. Refer to the "LetterCount" program example in Chapter Seven Activities for guidance. ### Seat Assignment Logic The program checks the availability of a seat by scanning the array. An 'X' in the array indicates the seat is not available. - **Logic for Seat Availability:** - If the seat is available, assign 'X' at that position in the array. - If unavailable, notify the passenger and request a different selection using the `displaySeats` method after each entry. ### Example Layout After Seat Assignments Once some seats have been assigned, the seating arrangement might resemble: ``` 1 A B C X 2 A B C D 3 A B C X 4 A B C D 5 A B C D ``` **Note:** Continue processing seat requests until the user enters "1" for the seat. This programming exercise helps reinforce understanding of arrays, user input handling, and control structures in Java.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
ADT and Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education