Answered step by step
Verified Expert Solution
Link Copied!

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 0 of
any coin. If you are asked to decreaseQuantity below 0, just set it to 0.
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.format("%4.2f",amount));
C#:
return($+amount.ToString("F2"));
An override of toString (java) or ToString (C#) which returns a string like $3.25 in
$0.25 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 0 of
any note. If you are asked to decreaseQuantity below 0, just set it to 0.
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.format("%4.2f",amount));
C#:
return($+amount.ToString("F2"));
An override of toString (java) or ToString (C#) which returns a string like $32.00
in $1.00 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 twenties=new Notes(20);
Notes tens=new Notes(10);
Notes fives=new Notes(5);
Notes ones=new Notes(1);
Coins quarters=new Coins(0.25f,0.2f);
Coins dimes=new Coins(0.10f,0.08f);
Coins nickels=new Coins(0.05f,0.176f);
Coins pennies=new Coins(0.01f,0.088f);
dimes.increaseQuantity(41);
nickels.increaseQuantity(17);
pennies.increaseQuantity(132);
ones.increaseQuantity(33);
fives.increaseQuantity(12);
tens.increaseQuantity(2);
twenties.increaseQuantity(5);
Next print out how much money you have in $20 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 $10 notes.
Print out how much money you have in $5 notes.
Print out how much money you have in $1 notes.
Print out how much money you have in quarters ($0.25 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
$20 notes, add that to the total value of $10 notes, $5 notes, $1 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 $219.27 total
weight is 17.888oz
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 $22.50, youd likely think to give them 2 ten
dollar notes, 2 one dollar notes, and 2 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 2 ten dollar notes, 2 one dollar notes,
and 5 dimes.
Regardless of th

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications Dexa 2023 Workshops 34th International Conference Dexa 2023 Penang Malaysia August 28 30 2023 Proceedings

Authors: Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil ,Bernhard Moser ,Atif Mashkoor ,Johannes Sametinger ,Maqbool Khan

1st Edition

303139688X, 978-3031396885

More Books

Students also viewed these Databases questions

Question

=+4. What information remains to be obtained?

Answered: 1 week ago