Homework #1


You must submit your work to your instructor before midnight on due date. Failure to do so will result in late penalties, see the syllabus for grading detail.


Implement a class Coin that describes a coin with a name (e.g. dime) and a value (e.g. 10 cents).

Implement a class Wallet that describes a collection of coins. Supply a method add() to add a coin to a purse, and a method printContent() that prints out to standard output the contents of a purse in the following format:

coinName (coinValue): numberOfCoins

Example

penny (1 cent): 11
dime (10 cents): 3
nickel (5 cents): 2
Total value: 51 cents

In order to test your Wallet class you'll also implement a class WalletTest whose main() method does the following:

  • Constructs an empty wallet
  • Prompts the user to enter the name of a coin (e.g. dime), or an empty string to quit
  • Prompts the user to enter the value of a coin (e.g. 10)
  • Adds the coin to the wallet
  • Prints the contents of the wallet
  • Goes to the 2nd bullet point above
In addition to the above, your Wallet should supply a method equals() that tests whether two coins have the same name and value.

Don't forget to re-read the syllabus to make sure you understand all the deliverables for assignments in this class, including this one.


Last update: Feb 1, 2009 Virgil Bistriceanu cs445 Computer Science

$Id: hw1.html,v 1.1 2009/02/02 00:30:33 virgil Exp $