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          ...
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...
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...
Write a java method that creates a two dimensional char array after asking the user to...
Write a java method that creates a two dimensional char array after asking the user to input a String text (for example, "Sara" which is entered by the user)  and String key consisting of integers (for example, 2314) only, such that int rows=(int)Math.ceil(text.length()/key.length())+1; int columns= key.length(); The method fills the 2d array with letters a String entered by the use (column by column). The method then shifts the columns of the array based on key. For example, if the user enter...
In Java please Your program will sort a two dimensional array (5 * 4) based on...
In Java please Your program will sort a two dimensional array (5 * 4) based on the following: The entire array should be sorted using bubble sort based on the 1st column in ascending order and display the entire array. Reset the array to its original contents. The entire array should again be sorted using selection sort based on the 2nd column in descending order and display the entire array. Reset the array to its original contents. The entire array...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT