If anyone out there is begining OOAD, like me, you might be interested in the second maintenace task proposed by Russell in his
ATM simulation example.
It says like that:
Many ATM's have cash dispensers that can handle two different denominations of bills - often $20 and $5 - which allows a user to request cash in any amount that is a multiple of $5. Suppose the cash dispenser in the example (which only handles $20 bills) were replaced with such a dispenser. What changes would be needed to take advantage of the enhanced capabilities of such a dispenser?
I have modified it to allow bills of $50 , $20 and $5 to be dispensed in combinations, that follow that order as long as there are bills available, to satisfy the requested amount.
You can enter 0 for any amount to simulate an ATM that only holds certain types of bills.
This is a description of the changes I made:
You can jump to e where the question is.
a) The CashDispenser class no longer holds an attribute cashonHand of type Money, but an instance of purse.
b) The methods checkCashOnHand and dispenseCash in the class CashDispenser were modified to deal with purse instead of cashonHand.
c) The methods that in the System Startup took a simple instance of Money, take now an array of Money to holds the amounts introduced by the operator in different types of bills.
d) The class Money was added a module method.
e) The class Purse holds an array of Money representing each element an amount of dollars in different types of bills. First one the dollars the cashier has in $50 bills, second one in $20 bills, and the third in $5. Thus I decided to model the types of bills as Money instances. No new classes were added here. However these instances of Money are somehow treated differently by the program. For instance at the time of creation the number of bills of type $50 is multiplied by 50, while creating the instance that holds the amount hold in $20 bills, is multiplied by 20. Also the algorithm that calculate in how many bills of a certain type will be decomposed the amount to be dispensed, has to be aware of which type is dealing with. Though the way in which the program deals with the variation of the types of bills present seems under control, would have a more object oriented solution added some value ? For instance, having modelled $50, $20 and $5 as units of Money.
The way the program deals with the variation in the types of bills is just figuring out how many different bills are possible, and the programmer should create the Money array of the maximum possible length.
This the new
ATM2.jar ATM simulation ATM simulation 2 ATM simulation 4 [ September 01, 2002: Message edited by: Jose Botella ]
[ September 03, 2002: Message edited by: Jose Botella ]