Question
JAVA Please follow the instructions exactly - no more and no less. Pick the best data types and follow all Java conventions regarding naming and
JAVA Please follow the instructions exactly - no more and no less. Pick the best data types and follow all Java conventions regarding naming and the use of public and private modifiers. You may assume the user enters an appropriate value when prompted (i.e., you do not have to check that a user entered an integer if that is what you asked for). 1. Create a class PiggyBank. It is to keep track of the number of quarter, half-dollar and dollar coins inside of it. It should have instance variables for the count of each type of coin. It should have a single constructor that takes no parameters. It should have an accessor method, countMoney that takes no parameters and returns the total value (in cents) of the PiggyBank. It should have mutator methods addQuarters, addHalfDollars and addDollars to add quantities of each type of coin ( methods like addQuarters(numPennies) ). The PiggyBank should *not* ask the user for any information. That should be done by the PiggyBankTester program. 2. Create a class PiggyBankTester that is to have 1 method named main. It should contain a loop that in each execution of the loop asks the user for the type of coin and the number of that type of coin to add. That numbers of coins should then be added to the PiggyBank. If the user enters an X or 'x', the loop should terminate. After the loop is complete, the program should display the value of the PiggyBank. Do not worry about testing for valid input, but the user may enter the type of coin in either upper or lower case (e.g., 'Q' or 'q'). Here is a sample run of the program: Welcome to the PiggyBankTester! What type of coin to add (Q, H, D or X to exit)? Q How many do you wish to add? 3 What type of coin to add (Q, H, D or X to exit)? D How many do you wish to add? 2 What type of coin to add (Q, H, D or X to exit)? H How many do you wish to add? 2 What type of coin to add (Q, H, D or X to exit)? D How many do you wish to add? 1 What type of coin to add (Q, H, D or X to exit)? X The PiggyBank now contains 475 cents. Goodbye!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started