Homework #4


Submit your work work on the Blackboard before midnight the day the homework is due. Failure to do so will result in late penalties, see the syllabus for grading detail.

Here are the requirements for your Blackboard submission:

  • Attach the assignment as a compressed archive file (.zip, .tgz, .tbz2, .rar)
  • The name of the file should be: firstName-lastName-HW-assignmentNumber.extension (e.g. Jane-Doe-HW-4.zip)
  • Include your e-mail address in the Comment field when submitting the assignment through the Digital Drop Box
  • If for any reason you are submitting the assignment more than once, indicate this in the Comment field by including the word COMPLEMENT

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

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

coinName (coinValue): numberOfCoins

Example

penny (1 cent): 11
dime (10 cents): 3
green (7 petals): 2
euro (100 eurocents): 5

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 cents)
  • Adds the coin to the wallet
  • Prints the contents of the wallet
  • Goes to the 2nd bullet point above

Please note that the following two coins are different:

dime (10 cents)
Dime (10 cents)

Speaking of coins being the same or different, you should supply a method equals() that tests whether two coins have the same name and value.

Make sure you have reasonable automated unit testing for the code you've written.



$Id: hw4.html,v 1.1 2015/08/24 22:35:02 virgil Exp $