CJCoding With Joseph
15free / daySign inCreate account

A field declared in an interface is a constant: it is public static final even though none of those words are written. A class that implements the interface can use the constant by its plain name. CartRules holds the limit MAX_ITEMS. Complete canAdd() and the guard inside add() in Cart.

Requirements: 1. canAdd() returns true while count is less than MAX_ITEMS, and false once the cart is full. 2. add() returns false and leaves count alone when canAdd() is false. Otherwise it raises count by one and returns true (those two lines are written). 3. Use the constant MAX_ITEMS, not the number 3, so the cart follows the interface if the limit ever changes. 4. Do not change CartRules.

Do NOT write a main method.

Expected output

true
true
true
true
false
false
3

= newline. The output ends with a newline, so print one after the last line.

Hints2 available
Topics
InterfacesClasses
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (sysout, psvm, fori)

Your output

Run your code to see the output here...

Test cases

Run your code to see test case results.