ITEC 120 Back to Assignment index page
   
Assignment 5 - Saving coins
Submit your program to a folder called RU11 in your directory on neelix.

Description:  Design and implement a class called MonetaryCoin that is derived from the Coin class from Chapter 4: Coin.java. Store a value in MonetaryCoin that will represent its value (1, 5, 10, or 25 only). Notice that the ability to flip a coin is inherited from the parent.

Write a driver to simulate this situation: Joe plays a little game with all the coins he gets. He flips them, and, if they are heads, he puts them into his piggy bank. (He's saving to buy a computer.) If they are tails, he puts them in his pocket to spend later.

Your program will ask the user for coins, flip them, and keep a total of the value of all the heads (for the bank) and all the tails (to spend).

Here's what the driver program will do:

Program outputs: What kind of coin do you have?
P-Penny, N-Nickel, D-Dime, Q-Quarter, X-eXit
User inputs: q
Program outputs: QUARTER: Tails
What kind of coin do you have?
P-Penny, N-Nickel, D-Dime, Q-Quarter, X-eXit
User inputs: d
Program outputs: DIME: Tails
What kind of coin do you have?
P-Penny, N-Nickel, D-Dime, Q-Quarter, X-eXit
User inputs: N
Program outputs: NICKEL: Heads
What kind of coin do you have?
P-Penny, N-Nickel, D-Dime, Q-Quarter, X-eXit
User inputs: D
Program outputs: DIME: Tails
What kind of coin do you have?
P-Penny, N-Nickel, D-Dime, Q-Quarter, X-eXit
User inputs: p
Program outputs: PENNY: Heads
What kind of coin do you have?
P-Penny, N-Nickel, D-Dime, Q-Quarter, X-eXit
User inputs: D
Program outputs: DIME: Heads
What kind of coin do you have?
P-Penny, N-Nickel, D-Dime, Q-Quarter, X-eXit
User inputs: q
Program outputs: QUARTER: Tails
What kind of coin do you have?
P-Penny, N-Nickel, D-Dime, Q-Quarter, X-eXit
User inputs: Q
Program outputs: QUARTER: Tails
What kind of coin do you have?
P-Penny, N-Nickel, D-Dime, Q-Quarter, X-eXit
User inputs: d
Program outputs: DIME: Tails
What kind of coin do you have?
P-Penny, N-Nickel, D-Dime, Q-Quarter, X-eXit
User inputs: x
Program outputs: You have put 0 dollars and 16 cents into the bank.
You have put 1 dollar and 5 cents into your pocket.

Points will be given for a good design using inheritance (Coin is the parent, MonetaryCoin is the child.). Also, in your driver, make sure to handle invalid input from the user, and handle capitol or lowercase letters as input.


TURNING IN YOUR PROGRAM: You will turn in three files: Coin.java, MonetaryCoin.java, and program5.java. PLEASE name the files as suggested: it expedites the grading process.