Track a shared seat pool

A theatre uses the following Java class to track a pool of 24 available seats and the seats reserved by each booking object. The statements run once in a fresh program, in the order shown.


Java
class Booking {
    static int available = 24;
    int reserved = 0;
}


Java
Booking first = new Booking();
first.reserved += 6;
Booking.available -= 6;

Booking second = new Booking();
// Checkpoint: Second booking created

second.reserved += 4;
Booking.available -= 4;
// Checkpoint: Second reservation completed

first.reserved -= 2;
Booking.available += 2;
// Checkpoint: Two seats returned


Complete the table with the value of each field at each checkpoint. Enter exact whole numbers of seats. Assume no other code changes these fields.

CheckpointBooking.available (seats)first.reserved (seats)second.reserved (seats)
Second booking created
Second reservation completed
Two seats returned

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Instance Variables and Class Variables Questions: