Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

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.
expand button
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.
expand button
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
Check Mark
Knowledge Booster
Background pattern image
Computer Science
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
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education