Java Reference
In-Depth Information
public void addAccount(int accountNumber,
double initialBalance)
public void deposit(int accountNumber, double
amount)
public void withdraw(int accountNumber,
double amount)
public double getBalance(int accountNumber)
΢ Exercise P7.2. Implement a class Purse . A purse contains a collection of
coins. For simplicity, we will only store the coin names in an
ArrayList<String> . (We will discuss a better representation in
Chapter 8 .) Supply a method
void addCoin(String coinName)
Add a method toString to the Purse class that prints the coins in the
purse in the format
Purse[Quarter,Dime,Nickel,Dime]
΢ Exercise P7.3. Write a method reverse that reverses the sequence of coins
in a purse. Use the toString method of the preceding assignment to test
your code. For example, if reverse is called with a purse
Purse[Quarter,Dime,Nickel,Dime]
then the purse is changed to
Purse[Dime,Nickel,Dime,Quarter]
΢ Exercise P7.4. Add a method to the Purse class
public void transfer(Purse other)
that transfers the contents of one purse to another. For example, if a is
Purse[Quarter,Dime,Nickel,Dime]
327
328
and b is
Search WWH ::




Custom Search