← Back to Encapsulation
Question 591
Inventory Stock Control
Inventory Stock Control
TheInventoryclass tracks a private fieldquantitythat starts at 0. AddAddStock(int amount)that increases the quantity but ignores amounts of 0 or less,RemoveStock(int amount)that removes stock only when there is enough (returningtrueon success andfalseotherwise), and a read-only propertyQuantity. The tester prints the result of a removal, then the remaining quantity. Do NOT write aMainmethod. After adding 10 and removing 4 the program prints the output shown in Expected Output. If a removal is larger than the stock it is refused, so adding 5 then removing 9 prints: False 5
Expected Output:
True 6
= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
Encapsulation
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cw, cr, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.