## ChangeDispenserController Class ### Methods #### calculateChange(unitsTendered, price) **unitsTendered:** An array of instances of some kind of MonetaryUnit subclass. The units tendered all have the same currency and that the amount tendered is greater than price. **price:** Number. You can assert that the units tendered match the currency for price, which is why price is just a number. **Returns** true if change can succesfully be dispensed, otherwise returns false to issue a refund and cancel the product. ## ChangeDispenser Class An instance of ChangeDispenser is programmed to physically know what change it has to dispense and physically how to dispense it. Assume that ChangeDispenser is a thin JavaScript layer over native code. ### Properties For every currency unit available, the JavaScript layer dynamically defines properties that match the class name of the monetary units using Object.defineProperty. It defines the properties as read-only properties using getter methods that return new arrays. The new arrays returned from these properties are not referenced internally. For example, `someChangeDispenserInstance.UnitedStatesPennyUnit` would give you an array containing all available instances of UnitedStatesPennyUnit. ### Methods #### unitsAvailable(currency) Describes the types of monetary units available to dispense. **currency:** A String value for the currency, i.e. "USD". **Returns** an array of objects describing the availablity of monetary units that match the curreny passed in, sorted in descending monetaryValue: ``` [ // ... { propertyName: String (i.e. "UnitedStatesDimeUnit"), unitInfo: { monetaryValue: 0.1, currency: "USD", currencySymbol: "$" } }, // ... ] ``` #### dispense(units) Physically dispenses change for all of the monetary unit instances that you pass in. **units:** An array of instances of some kind of MonetaryUnit subclass. **Throws** an error synchronously if any instance is not in the monetary unit properties, i.e. `someChangeDispenserInstance.UnitedStatesPennyUnit`.