1. Member
Join Date
Sep 2011
Location
Richmond, VA
Posts
1
Rep Power
0

## Making Change

My second assignment for my intro to programming course is to make change:

Problem: Given the cost of an item, the number of items bought, and the amount tendered for the purchase, you should calculate the change to be given by specifying the number of each type of bill and coin to be used.

Input: The input to this program will consist of three values: the cost of an item, the number of items being bought, and the amount of money given to pay for the total purchase. You should have your program print out helpful prompts so that the user knows what values to input.

Output: You should echo the input data and print out the manner in which the change is to be given. For example,
Each item is \$0.46.
You bought 6 items.
You gave me \$20.00.
1 ten dollar bill
1 five dollar bill
2 one dollar bills
2 dimes
4 pennies

So far I have the input parts done, but I don't even know where to begin looking to start making change. I am so new to Java it hurts. Please help!

2. ## Re: Making Change

How would you do it manually?
Given an amount you need to remove some number of the biggest valued money first.
Use division, multiplication and subtraction.
Then move down in value and continue.

3. ## Re: Making Change

One piece of advice: Be weary of using doubles or floats to represent money amounts. Try using DecimalFormat, or String manipulation and integers to represent all money in cents.

4. ## Re: Making Change

Originally Posted by Norm
Given an amount you need to remove some number of the biggest valued money first.
That only applies if you want to return the minimum number of coins and bills and that only works for monetary units which are so called 'spanning bases'. e.g. if there were coins of 1, 2, 8 and 10 and you had to pay 16 (cents?) it'd be better to pay 2x8 cents instead of 1x10 and 4x2 cents. b.t.w. the 1,2,5 systems (US\$, euros etc.) are more efficient than e.g. the old Dutch guilder system (1, 2.5, 5)

kind regards,

Jos (<--- for all your useless knowledge ;-)

5. ## Re: Making Change

How I hated the 2.5 guilders.

6. ## Re: Making Change

Originally Posted by Norm
How I hated the 2.5 guilders.
Why? You couldn't see the difference between 1 guilder and 2.5 guilders?

kind regards,

Jos

7. ## Re: Making Change

I'm not sure. Just when I got a handful of coins as change, I was never sure how much I had gotten.

8. ## Re: Making Change

Originally Posted by Norm
I'm not sure. Just when I got a handful of coins as change, I was never sure how much I had gotten.
If it was a Dutchmen who gave you the change you could've counted on it that it wasn't enough ;-) In the old days we even had 1.5 guilder coins (just to upset the bloody foreigners ;-) Now we have those silly euros and I still don't know the difference between them ... given the sad state of the stock markets they're gone soon.

kind regards,

Jos

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•