Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In this assignment, you will model US currency with objects, creating objects for each note and coin. Tasks: First write a class called Coins that
In this assignment, you will model US currency with objects, creating objects for each
note and coin.
Tasks:
First write a class called Coins that has:
A private integer called quantityOnHand
A private float called denomination
A private float called weight
A constructor which takes two floats denomination and weight and sets the
object attributes.
A method called getTotalWeight which returns a float representing the total
weight of that coin weight quantityOnHand
A method called getTotalValue which returns a float representing the total value
of this coin denomination quantityOnHand
A method called increaseQuantity which takes in a quantity int and increases
the quantityOnHand by that amount.
A method called decreaseQuantity which takes in a quantity int and decreases
the quantityOnHand by that amount. Note, you can never have less than of
any coin. If you are asked to decreaseQuantity below just set it to
A method called getQuantityOnHand which takes in no parameters, and returns
the value of the quantityOnHand attribute an int
A method called printPretty which takes in a float called amount, and returns a
string. The body of the method will be:
Java:
return$String.formatfamount;
C#:
return$amount.ToStringF;
An override of toString java or ToString C# which returns a string like $ in
$ coins The first value should be the total value of the coin, the second
value should be the denomination of the coin. Hint printPretty may come in
handy here.
Next write a class called Notes which has:
A private integer called quantityOnHand
A private integer called denomination
A constructor which takes one integer called denomination and sets the object
attributes.
A method called getTotalValue which returns a int representing the total value of
this note denomination quantityOnHand
A method called increaseQuantity which takes in a quantity int and increases
the quantityOnHand by that amount.
A method called decreaseQuantity which takes in a quantity int and decreases
the quantityOnHand by that amount. Note, you can never have less than of
any note. If you are asked to decreaseQuantity below just set it to
A method called getQuantityOnHand which takes in no parameters, and returns
the value of the quantityOnHand attribute an int
A method called printPretty which takes in a float called amount, and returns a
string. The body of the method will be:
Java:
return$String.formatfamount;
C#:
return$amount.ToStringF;
An override of toString java or ToString C# which returns a string like $
in $ notes The first value should be the total value of the note, the second
value should be the denomination of this note.
Finally, write a main method. Start it with the following code:
Notes twentiesnew Notes;
Notes tensnew Notes;
Notes fivesnew Notes;
Notes onesnew Notes;
Coins quartersnew Coinsff;
Coins dimesnew Coinsff;
Coins nickelsnew Coinsff;
Coins penniesnew Coinsff;
dimes.increaseQuantity;
nickels.increaseQuantity;
pennies.increaseQuantity;
ones.increaseQuantity;
fives.increaseQuantity;
tens.increaseQuantity;
twenties.increaseQuantity;
Next print out how much money you have in $ notes. Hint, you should be able
to use the toString or ToString override from the Notes class.
Print out how much money you have in $ notes.
Print out how much money you have in $ notes.
Print out how much money you have in $ notes.
Print out how much money you have in quarters $ coins Hint, again, use
the toString or ToString override in the Coin class..
Print out how much money you have in dimes
Print out how much money you have in nickels
Print out how much money you have in pennies.
Calculate how much money you have in total. Hint, youll get the total value of
$ notes, add that to the total value of $ notes, $ notes, $ notes, quarters,
dimes, nickels and pennies.
Calculate how much all the coins weigh. Hint, get the total weight of quarters,
add that to the total weight of dimes, nickels and pennies.
Print out a correct statement in the following format Total Money is $ total
weight is oz
Next, ask the user how much money they want: How much do you need?
Read in their answer a float
Next, you are going to figure out how many of each note and coin youd have to
give the user to equal the amount they requested.
For example, if the user needs $ youd likely think to give them ten
dollar notes, one dollar notes, and quarters. However, in this case you
dont have any quarters you know this if you look at your output from
above So instead, youd give them ten dollar notes, one dollar notes,
and dimes.
Regardless of th
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