Question

In: Computer Science

*****IN JAVA**** Implement a theater seating chart  as a two-dimensional array of ticket prices, like this: {10,...

*****IN JAVA****

Implement a theater seating chart  as a two-dimensional array of ticket prices, like this:

{10, 10, 10, 10, 10, 10, 10, 10, 10, 10}

{10, 10, 10, 10, 10, 10, 10, 10, 10, 10}

{10, 10, 10, 10, 10, 10, 10, 10, 10, 10}

{10, 10, 20, 20, 20, 20, 20, 20, 10, 10}

{10, 10, 20, 20, 20, 20, 20, 20, 10, 10}

{10, 10, 20, 20, 20, 20, 20, 20, 10, 10}

{20, 20, 30, 30, 40, 40, 30, 30, 20, 20}

{20, 30, 30, 40, 50, 50, 40, 30, 30, 20}

{30, 40, 50, 50, 50, 50, 50, 50, 40, 30}

Write a code snippet that:

- uses a for loop to print the array with spaces between the seat prices

- prompts users to pick a row and a seat using a while loop and a sentinel to stop the loop.

- outputs the seat price to the user.

Solutions

Expert Solution

Source Code:

Output:

Code in text format (See above images of code for indentation):

import java.util.*;

/*class definition*/

public class seatingChart

{

    /*main method*/

    public static void main(String[] args)

    {

        /*Scanner class to read input from the user*/

        Scanner scnr=new Scanner(System.in);

        /*2D array initialization*/

        int[][] prices={{10, 10, 10, 10, 10, 10, 10, 10, 10, 10},

                        {10, 10, 10, 10, 10, 10, 10, 10, 10, 10},

                        {10, 10, 10, 10, 10, 10, 10, 10, 10, 10},

                        {10, 10, 20, 20, 20, 20, 20, 20, 10, 10},

                        {10, 10, 20, 20, 20, 20, 20, 20, 10, 10},

                        {10, 10, 20, 20, 20, 20, 20, 20, 10, 10},       

                        {20, 20, 30, 30, 40, 40, 30, 30, 20, 20},

                        {20, 30, 30, 40, 50, 50, 40, 30, 30, 20},

                        {30, 40, 50, 50, 50, 50, 50, 50, 40, 30}

                        };

        /*variables*/

        int i,j,k=0,row,seat;

        /*print array with spaces*/

        for(i=0;i<9;i++)

        {

            for(j=0;j<10;j++)

            {

                System.out.print(prices[i][j]+" ");

            }

            System.out.println();

        }

        /*using while loop */

        while(true)

        {

            /*prompt the user to enter row number*/

            System.out.print("Enter a row number(1-9) or -1 to exit: ");

            row=scnr.nextInt();

            /*use sentinel to exit*/

            if(row==-1)

                break;

            /*read seat number*/

            System.out.print("Enter a seat number(1-10) : ");

            /*display price of seat*/

            seat=scnr.nextInt();

            System.out.println("The price of seat is: "+prices[row-1][seat-1]);

        }

    }

}


Related Solutions

(c++ code) A theatre seating chart is implemented as a two-dimensional array of ticket prices, like...
(c++ code) A theatre seating chart is implemented as a two-dimensional array of ticket prices, like this:                 AISLE ROW      1           2             3             4             5             6             7             8             9              10 -------------------------------------------------------------------------------------------------------------- 10           10           10           10           10           10           10           10           10           10           10 9             10           10           10           10           10           10           10           10           10           10 8             10           10           10           10           10           10           10           10           10           10 7             10           10           20           20           20           20           20           20           10           10 6             10           10           20           20          ...
A theater seating chart is implemented as a table of ticket prices, like this C1 C2...
A theater seating chart is implemented as a table of ticket prices, like this C1 C2 C3 C4 C5 C6 C7 C8 C9 C10 R1 10 10 10 10 10 10 10 10 10 10 R2 10 10 10 10 10 10 10 10 10 10 R3 10 10 10 10 10 10 10 10 10 10 R4 10 10 20 20 20 20 20 20 10 10 R5 10 10 20 20 20 20 20 20 10 10 R6...
To conduct an experiment, a movie theater increased movie ticket prices from $9 to $10 and...
To conduct an experiment, a movie theater increased movie ticket prices from $9 to $10 and measured the change in ticket sales. The theater then gathered data over the following month to determine whether the price increase was profitable. Assume total costs to the theater are the same, whether the price of a ticket is $9 or $10. In order for the ticket price to have been profitable over the month, the elasticity of demand for movie tickets must be...
Theater tickets for a hit show have four prices depending on seating. The prices ae $50,...
Theater tickets for a hit show have four prices depending on seating. The prices ae $50, $100, $150 and $200. The probability a ticket sells for $50 is .4. The probability it sells for $100 is .15. The probability it sells for $150 is .2. Find the probability a ticket sells for $200. Find the expected cost (mean cost) of a ticket. Find the standard deviation for the cost of a ticket Find the variance for the cost of a...
Write a Java program that will use a two-dimensional array and modularity to solve the following...
Write a Java program that will use a two-dimensional array and modularity to solve the following tasks: Create a method to fill the 2-dimensional array with (random numbers, range 0 - 30). The array has rows (ROW) and columns (COL), where ROW and COL are class constants. Create a method to print the array. Create a method to find the largest element in the array Create a method to find the smallest element in the array Create a method to...
Write a Java program that will use a two-dimensional array and modularity to solve the following...
Write a Java program that will use a two-dimensional array and modularity to solve the following tasks: 1. Create a method to generate a 2-dimensional array (random numbers, range 0 - 500). The array has ROW rows and COL columns, where ROW and COL are class constants. 2. Create a method to print the array. 3. Create a method to find the largest element in the array 4. Create a method to find the smallest element in the array 5....
Write a Java program that will use a two-dimensional array and modularity to solve the following...
Write a Java program that will use a two-dimensional array and modularity to solve the following tasks: Create a method to generate a 2-dimensional array (random numbers, range 0 - 500). The array has ROW rows and COL columns, where ROW and COL are class constants. Create a method to print the array. Create a method to find the largest element in the array Create a method to find the smallest element in the array Create a method to find...
IN JAVA Write a program that uses a two-dimensional array to store the highest and lowest...
IN JAVA Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. Prompt the user for 12 months of highest and lowest.   Write two methods : one to calculate and return the average high and one to calculate and return the average low of the year. Your program should output all the values in the array and then output the average high and the average low. im trying to...
Create a two-dimensional array A using random integers from 1 to 10. Create a two-dimensional array B using random integers from -10 to 0.
This program is for C.Create a two-dimensional array A using random integers from 1 to 10. Create a two-dimensional array B using random integers from -10 to 0. Combine the elements of A + B to create two- dimensional array C = A + B. Display array A, B and C to the screen for comparison. (Note a[0] + b[0] = c[0], a[1] + b[1] = c[1], etc.)
Write a Java program that will use a two-dimensional array to solve the following tasks: 1....
Write a Java program that will use a two-dimensional array to solve the following tasks: 1. Create a method to generate a 2-dimensional array (random numbers, range 0 - 500). The array has ROW rows and COL columns, where ROW and COL are class constants. 2. Create a method to print the array. 3. Create a method to find the largest element in the array 4. Create a method to find the smallest element in the array 5. Create a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT