Java Reference
In-Depth Information
΢΢΢Project 3.1. In this project, you will enhance the BankAccount class
and see how abstraction and encapsulation enable evolutionary changes
to software.
Begin with a simple enhancement: charging a fee for every deposit and
withdrawal. Supply a mechanism for setting the fee and modify the
deposit and withdraw methods so that the fee is levied. Test your
resulting class and check that the fee is computed correctly.
Now make a more complex change. The bank will allow a fixed number
of free transactions (deposits or withdrawals) every month, and charge
for transactions exceeding the free allotment. The charge is not levied
immediately but at the end of the month.
Supply a new method deductMonthlyCharge to the
BankAccount class that deducts the monthly charge and resets the
transaction count. Produce a test program that verifies that the fees are
calculated correctly over several months.
΢΢΢Project 3.2. In this project, you will explore an object-oriented
alternative to the ȒHello, Worldȓ program in Chapter 1 .
Begin with a simple Greeter class that has a single method,
sayHello . That method should return a string, not print it. Use BlueJ
to create two objects of this class and invoke their sayHello methods.
That is boringȌof course, both objects return the same answer.
Enhance the Greeter class so that each object produces a customized
greeting. For example, the object constructed as new Greeter(Ñ
DaveÑ) should say ÑHello, DaveÑ . (Use the concat method to
combine strings to form a longer string, or peek ahead at Section 4.6 to
see how you can use the + operator for the same purpose.)
Add a method sayGoodbye to the Greeter class.
Search WWH ::

Custom Search