A recreation-centre account starts with 20 tokens, and each pool visit costs 2 tokens. The Java program below does not compile. The client statements belong inside a valid method.
Keep VisitCost unchanged and keep pass declared as VisitCost. Which pair of edits makes the concrete class and client compile, with used equal to 8 tokens and left equal to 12 tokens? No other edits are made.
interface VisitCost { int tokens(int visits); } class Pool implements VisitCost { public int tokens(long visits) { return (int) (2 * visits); } public int remaining() { return 20; } } // Inside a method: VisitCost pass = new Pool(); int used = pass.tokens(4); int left = pass.remaining();
Change the parameter to int visits; use int left = 20 - used;.
Keep the parameter as long visits; use int left = 20 - used;.
Change the parameter to int visits; use int left = Pool.remaining() - used;.
Change the parameter to int visits; keep int left = pass.remaining();.
Unlock full course notes by signing up
Tracing a shared operation
A print shop uses the Java interface and classes below. The client statements run inside a valid method. What value does total store, in pages? Give an exact integer, with zero decimal places.
What an interface guarantees
A Java photo editor defines Saveable as shown below. Its documentation says that save() must preserve the current image data. Which statements about this design are correct? Select every correct statement.
Counting obligations across combined contracts
A monitoring application uses the Java declarations below. Each table row describes a separate planned concrete class that has no method declarations of its own yet.
For each planned class, enter the minimum number of distinct method implementations it must add to compile. Count only obligations from the displayed interfaces. Classes without a named superclass extend Object; each added method supplies one required operation.
Combining competing default implementations
A Java application combines a saved display name with a current display name. The unrelated interfaces below both provide label(), so the implementing class explicitly combines their results.
VISIBILITY, FIRST, and SECOND are placeholders. Replace each with one Java keyword or interface name so that the class compiles and new CombinedName().label() returns exactly "saved/current". Preserve all other code.
Replace VISIBILITY with ________, FIRST with ________, and SECOND with ________.