2D Array, 6 pointsAbout 22 minutes · 6 points
A small theater sells tickets for numbered seats. Each seat is a
Seat object.public class Seat
{
/** Returns true if this seat has been sold and
* false otherwise.
*/
public boolean isSold()
{ /* implementation not shown */ }
// There may be instance variables, constructors,
// and methods that are not shown.
}The Theater class stores the seats in a 2D array. The first index is the row and the second index is the column.public class Theater
{
/** seats[r][c] is the seat in row r, column c.
* seats has at least one row and one column.
* No element is null.
*/
private Seat[][] seats;
/** Returns an array with one element per row:
* element r is the number of seats in row r of
* seats that have not been sold.
*/
public int[] openPerRow()
{ /* to be implemented */ }
// There may be instance variables, constructors,
// and methods that are not shown.
}Suppose seats holds the following 3 rows of 4 seats. col 0 col 1 col 2 col 3
row 0 sold open open sold
row 1 sold sold sold sold
row 2 open open sold openThen openPerRow returns the array {2, 0, 3}: row 0 has 2 open seats, row 1 has none and row 2 has 3. For a theater with a single row of 3 seats, none of them sold, openPerRow returns {3}.