Professional Documents
Culture Documents
Lab3 ElectronicPiggyBank
Lab3 ElectronicPiggyBank
1) Develop your ability to use if, else if, and else statements to control program flow.
2) Develop your ability to use while statements to control program flow.
3) Develop your ability to use equals() for strings.
Background
Your little brother, Timmy, just got a piggy bank. He starts to use it, but becomes tired of
always adding up how much he is putting in the piggy bank (so that he know how much he
has).. He asks you for help.
You tell Timmy – “I’m still learning, but I am sure that I can write you a program to count how
much you deposit each time. I will just need you to keep track of the total value after each
time you use the program.”
Your Task
Write an electronic piggy bank program that begins by asking the user:
How much money is the piggy bank so far?
Each time the user presses “p”, “n”, “d”, or “q”, add the value of the coin to the total balance,
display the new total balance, and prompt the user to enter their next selection without
redrawing the menu.
When the user presses “e”, display the final balance, thank the user, and exit.
Grading
MENU:
(p) - Deposit a penny.
(n) - Deposit a nickel.
(d) - Deposit a dime.
(q) - Deposit a quarter.
(e) - Exit program.
Please press a letter to select an option:
p
Invalid option.
Please press a letter to select an option:
e