Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The seating map for a particular performance at a theater contains 70 rows of 10

ID: 3572416 • Letter: T

Question

The seating map for a particular performance at a theater contains 70 rows of 100 seats each. Using an array where applicable, develop the logic for a program that allows a user to continuously enter each household size and then a) Allows a user to continuously enter a row number and seat number until they enter an appropriate sentinel value for the row number in order to stop entering input. Each time the user enters a valid row and seat number, the program determines if that seat is available, and if so, marks it as reserved with an “X” (available seats are not marked in any way). Page 3 of 3 b) Once the user quits, the program outputs i) each row number followed by the seat numbers in that row that have been reserved ii) the total number of reserved seats iii) the total number of available seats This seating map applies only to this particular show. For other shows, the seating map may contain a different number of rows and seats per row, and the program must be capable of being modified for those by editing only two lines of code.

I do not want any specific programming language.

I know the declarations and I understand how to do the array, but I can't figure out how to write it out myself. Help????

Explanation / Answer

import java.util.*;

public class Seating
{
    public static void main(String args[])
    {
        int row, seat, rnum, snum, available, reserved = 0;
        String sentinel = "e"; //sentinel value
        String input;
        // entering theatre size
        System.out.println("Please enter no. of rows in theater: ");
        row = scanInput();
        System.out.println("Please enter no. of seats in each row: ");
        seat = scanInput();
        char[][] household = new char[row][seat];
        for(int i = 0; i < row; i++)
        {
            for(int j = 0; j < seat; j++)
            {
                household[i][j] = 'O'; // To make decision.
            }
        }
        available = row * seat;
        while(sentinel.equals("e")) // loop will continue until user don't enter sentinel value q to quit.
        {
            System.out.println("Please enter row no. between 1 to "+ row +" or 'q' to quit: ");
            Scanner scan2 = new Scanner(System.in);
            input = scan2.next();
            if(!input.equalsIgnoreCase("q"))
            {
                rnum = Integer.parseInt(input);
                rnum -= 1; // Because array starts from 0 and user will input from 1.
                System.out.println("Please enter seat no. between 1 to "+ seat +" : ");
                snum = scanInput();
                snum -= 1; // Because array starts from 0 and user will input from 1.
                if(household[rnum][snum] == 'O')
                {
                    household[rnum][snum] = 'X'; //marking seats with 'X'.
                    available -= 1; // counting no. of available seats.
                    reserved += 1; // counting no. of reserved seats.
                }
                else
                {
                    System.out.println("Please enter valid row and seat no..");
                }
                sentinel = "e";
            }
            else
            {
                sentinel = "q";
            }
        }
        System.out.println("Reserved rows and seats are: ");
        System.out.println("Row no. Seat no.");
        for(int i = 0; i < row; i++)
        {
            for(int j = 0; j < seat; j++)
            {
                if(household[i][j] == 'X')
                {
                    System.out.println(" " + (i+1) + " " + " " +(j+1));
                }
            }
        }
        System.out.println("Total no.of reserved seats = " + reserved);
        System.out.println("Total no. of available seats = " + available);
    }
    //scaning input
    public static int scanInput()
    {
        Scanner scan = new Scanner(System.in);
        return scan.nextInt();
    }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote