Booking through a shared pool

A recreation centre's Java program manages a shared pool of available admission slots. Assume a fresh execution, sequential calls, and no other code that changes availability.


Java
class PassPool {
    static int available = 36;

    int book(int requested) {
        available -= requested;
        return available;
    }

    static int check(int requested) {
        return available - requested;
    }

    static int bookThrough(PassPool desk, int requested) {
        int before = available;
        desk.book(requested);
        return before - available;
    }
}


The following statements execute in order inside main. The second booking requests one third of the value stored in quote; the division is exact in this execution.


Java
PassPool east = new PassPool();
east.book(7);
int quote = PassPool.check(5);
PassPool west = new PassPool();
int booked = PassPool.bookThrough(west, quote / 3);
int finalQuote = PassPool.check(booked);


Determine the final values of booked, PassPool.available, and finalQuote. Give each value in slots as an exact whole number.

Your answers

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 Static Keyword and Class Methods Questions: