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.
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.
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.
Unlock full course notes by signing up
Object access inside a static method
A Java monitoring program uses the following class. Assume s refers to an existing Sensor object when the program calls Sensor.inspect(s). Which statements about the method are true? Select all that apply.
Tracing a credit ledger
A Java application manages a shared balance of printing credits using the class below. Assume a fresh execution and no other calls.
The following statements execute in order inside main:
What value does combined hold? Answer in credits, to the nearest whole credit.
Separate calls or combined inputs
A delivery service bills each consignment in 600 g weight units, rounding any partial unit upward. Each consignment also incurs a fixed fee of 95 cents. For the masses used in this question, this Java class implements that pricing rule:
Java integer division discards the fractional part. Two items have masses of 2750 g and 850 g. Assume combining them adds no packaging mass and is permitted by the service.
Find these four quantities as exact integers:
A query during class initialization
A venue application loads this Java class for the first time. Predict its query results using the initialization rules supplied below.
For this problem, use these Java rules:
Before the explicit static field assignments run, all static int fields initially contain 0.