Question
First make a class called Coins that has: A private integer called quantityOnHand A private float called denomination A private float called weight A constructor
First make 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 make 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, make 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, you'll 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 you'd have to give the user to equal the amount they requested. For example, if the user needs $22.50, you'd likely think to give them 2 ten dollar notes, 2 one dollar notes, and 2 quarters. However, in this case you don't have any quarters (you know this if you look at your output from above). So instead, you'd give them 2 ten dollar notes, 2 one dollar notes, and 5 dimes. Regardless of the amount requested, your program must output the correct combination of notes and coins to equal that amount. One note/coin per line. Hint: Start with the $20 note. If they ask for an amount greater than $20, you'll keep giving them $20's until the amount left to give is less than 20. Then see if you should give them $10's, then $5's, then $1's, then Quarters, then Dimes, then Nickels, and finally Pennies. If at the end you don't have enough money (i.e. you still owe them more than 0.001), you should tell them that, and let them know how much you still owe them. (see examples below). Remember as you give them each note/coin, you should decrease the quantity of that note/coin that you have on hand. Finally, print out how much money you have left, and how much the coins weigh. Example Run: [User input in red] $100.00 in $20.00 notes. $20.00 in $10.00 notes. $60.00 in $5.00 notes. $33.00 in $1.00 notes. $0.00 in $0.25 coins. $4.10 in $0.10 coins. $0.85 in $0.05 coins. $1.32 in $0.01 coins. Total Money is $219.27 total weight is 17.888oz How much do you need? 42.47 Give them a $20 note Give them a $20 note Give them a $1 note Give them a $1 note Give them a dime Give them a dime Give them a dime Give them a dime Give them a nickel Give them a penny Give them a penny I have $176.80 left, it's total weight is 17.216oz
Step by Step Solution
3.53 Rating (163 Votes )
There are 3 Steps involved in it
Step: 1
Coins Class Java java public class Coins private int quantityOnHand private float denomination priva...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