Java Reference
In-Depth Information
381
PROGRAMMING EXERCISES
΢΢ Exercise P8.1. Implement the Coin class described in Section 8.2 .
Modify the CashRegister class so that coins can be added to the cash
register, by supplying a method
void enterPayment(int coinCount, Coin
coinType)
The caller needs to invoke this method multiple times, once for each type
of coin that is present in the payment.
΢΢ Exercise P8.2. Modify the giveChange method of the CashRegister
class so that it returns the number of coins of a particular type to return:
int giveChange(Coin coinType)
The caller needs to invoke this method for each coin type, in decreasing
value.
΢ Exercise P8.3. Real cash registers can handle both bills and coins. Design a
single class that expresses the commonality of these concepts. Redesign the
CashRegister class and provide a method for entering payments that
are described by your class. Your primary challenge is to come up with a
good name for this class.
΢ Exercise P8.4. Enhance the BankAccount class by adding preconditions
for the constructor and the deposit method that require the amount
parameter to be at least zero, and a precondition for the withdraw
method that requires amount to be a value between 0 and the current
balance. Use assertions to test the preconditions.
΢΢ Exercise P8.5. Write static methods
ȗ public static double sphereVolume(double r)
ȗ public static double sphereSurface(double r)
Search WWH ::




Custom Search