CJCoding With Joseph

Inventory Stock Control

The Inventory class tracks a private field quantity that starts at 0. Add AddStock(int amount) that increases the quantity but ignores amounts of 0 or less, RemoveStock(int amount) that removes stock only when there is enough (returning true on success and false otherwise), and a read-only property Quantity. The tester prints the result of a removal, then the remaining quantity. Do NOT write a Main method.

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.