A mutable Java ArrayList named values initially contains the record identifiers 11, 22, 33 and 44, in that order. A fresh iterator it traverses this list and supports remove().
Execute the operations in the table sequentially using this same iterator. No other code modifies the list. If an operation throws an exception, the test harness catches it and continues with the next row. A rejected removal leaves both the list and the iterator's state unchanged.
Complete both columns for every operation. For an operation's outcome, enter its returned integer or lowercase boolean, done for a successful void method, or the exact exception class name. Enter each list size as an exact integer number of records immediately after that operation.
Unlock full course notes by signing up
Parcel Total from a Traversal
A shipping program runs the following Java code with standard java.util imports. Each integer in masses is a parcel mass in kilograms, and the list remains unchanged.
What is the final value of total, in kilograms? Enter an exact integer, with no decimal places.
Returning the Selected Ticket
A Java ticket iterator should return the ticket numbers 3, 7, 11 and 15, in that order. Its integer field cursor starts at 3. Assume the required exception class is imported.
The following methods compile, but next() contains a logic error:
Repair only the expression in the final return statement, leaving every other line unchanged. Complete the statements using one exact Java variable name and two exact integers.
Counting Calls Before an Early Exit
A Java object named readings implements Iterable for integer sensor readings. Each fresh iterator returns 18, 25, 31, 46 and 52, in that order. The object records every invocation of iterator(), and its returned iterator records every invocation of hasNext() and next().
All three counters begin at zero immediately before this code runs. The methods do not invoke one another internally, and no other code accesses the object or iterator during this execution.
Determine the final numbers of calls to iterator(), hasNext() and next(). Enter each count as an exact integer number of calls.
Repairing Nested Traversal
A scheduling program should count every ordered pair of four session codes, including pairs that use the same code twice. Its target is all 16 ordered pairs. The unchanged list and current Java code are:
Which changes, applied separately to this code, produce the intended count? Select every correct change.