โ Back to Encapsulation
Question 501
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: True 6 If a removal is larger than the stock it is refused, so adding 5 then removing 9 prints: False 5
Expected Output:
True 6
Topics:
Encapsulation
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท 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.