Question
1. Your programming and documentation style should conform to the guidelines we have discussed. 2.Please complete the class with the name PiggyBankby following the directions
1.
Your programming and documentation style should conform to the guidelines we have
discussed.
2.Please complete the class with the name PiggyBankby following the directions below:
a.The following integer fields:
i.numPennies
ii.numNickels
iii.numDimes
iv.numQuarters
b.And a constructor that should initialize all fields to zero.
c.And the following mutator methods:
i.addPennies
ii.addNickels
iii.addDimes
iv.addQuarters
where the number of coins to be added is in the parameter. Note that if a negativenumber in passed to any of these methods, that value should
NOT be added to the appropriate field.
d. And an accessor method: i. getContents which returns how much is in the piggy bank. This method will require a local
variable for adding all the values together and returning a floating point value of the
dollar amount. There will be some arithmetic performed in this method.
e. And the following method is a combination of a mutator and an accessor:
i. breakTheBank where the contents are returned as a floating point value and all fields are set back to
zero. In it there must be a call to the getContents method before all fields are set back to zero.
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