Computer Science Canada ChangeMaker Help |
Author: | Grentex [ Sat Oct 10, 2015 3:29 pm ] | ||||
Post subject: | ChangeMaker Help | ||||
So I have to make a changemaker using methods and what not. Lab says Use the minimum number of coins. $1.39 also equals 0 quarters, 0 dimes, 0 nickels and 139 pennies, but you're not going to have a very successful career as a cashier if you make change in this way. In this second program, keep your ChangeMaker class flexible by NOT having it include any input or output to/from the console. This way, it can be used in a console application, windows application, or web application! Also, please note that I've included a toString() method which is a standard method that returns a string to describe the class. Also test with $1.15 to make sure you get the right answer. This number gets stored as 1.14999999, so it needs some rounding to get it right. Be sure to handle this in your solution. Tester class
Method Class
It was going fine but whenever you input 1.4999999 you suddenly lose a penny. In fact, after doing some testing apparently it always loses a penny whenever there is one quarter, one dime, and more than 2 pennies. For example:$0.43 equals 1 quarters, 1 dimes, 1 nickels, and 2 pennies. Working ones: $1.12 equals 4 quarters, 1 dimes, 0 nickels, and 2 pennies. $1.13 equals 4 quarters, 1 dimes, 0 nickels, and 2 pennies. $1.62 equals 6 quarters, 1 dimes, 0 nickels, and 2 pennies. $1.38 equals 5 quarters, 1 dimes, 0 nickels, and 2 pennies. $1.09 equals 4 quarters, 0 dimes, 1 nickels, and 4 pennies. Any help for this would be great. |
Author: | Insectoid [ Sat Oct 10, 2015 5:17 pm ] |
Post subject: | RE:ChangeMaker Help |
This is the result of floating point precision errors, and this is usually the assignment where students discover the problem. There's a really, really easy solution that involves not using floating point numbers at all. See if you can figure it out. |
Author: | Grentex [ Sat Oct 10, 2015 7:11 pm ] |
Post subject: | RE:ChangeMaker Help |
Alright you lost me, from what I can tell its telling me to use BigDecimal, which I can't use. So either I break the lab rules, or not be able to hand it in. great |
Author: | DemonWasp [ Sat Oct 10, 2015 9:25 pm ] |
Post subject: | RE:ChangeMaker Help |
You almost never get an assignment in school that's actually impossible -- if it looks impossible, then either you aren't reading the assignment correctly or you're missing some way of solving the problem. In this case, ask yourself: what is the smallest unit of currency you will need to handle? (hint: not dollars, since you sometimes need fractions of a dollar) |
Author: | Grentex [ Sun Oct 11, 2015 12:15 pm ] | ||
Post subject: | Re: RE:ChangeMaker Help | ||
DemonWasp @ Sat Oct 10, 2015 9:25 pm wrote: You almost never get an assignment in school that's actually impossible -- if it looks impossible, then either you aren't reading the assignment correctly or you're missing some way of solving the problem.
In this case, ask yourself: what is the smallest unit of currency you will need to handle? (hint: not dollars, since you sometimes need fractions of a dollar) If you are talking about essentially doing this
I does not work, I tried and then STILL ended up with 1 penny missing even though I am using penny as the the full amount. |
Author: | Insectoid [ Sun Oct 11, 2015 3:00 pm ] | ||
Post subject: | RE:ChangeMaker Help | ||
You're on the right track here. Tell me, why do you need to use doubles, or even decimal points, at all? |