Design and implement the class CupDispenser. Each CupDispenser object has a location and keeps track of the number of cups it currently contains. Define two constructors, set and get methods for each...


Design and implement the class CupDispenser. Each CupDispenser object has a location and keeps track of the number of cups it currently contains. Define two constructors, set and get methods for each data field, and the method toString. Also, define a method getOneCup that simply decrements the number of cups in the dispenser by 1. Demonstrate your class by creating several CupDispenser objects. Bonus: Define the method takeCupsFrom that removes all the cups from its argument, a CupDispenser object, and adds them to its receiving object. For example, if cd1 contains 10 cups, and cd2 contains 20 cups, after the call cd1.takeCupsFrom(cd2), cd1 will contain 30 cups and cd2 will be empty.



May 18, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here