Results 1 to 8 of 8

Thread: Making Change

  1. #1
    iamNovember is offline Member
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    1
    Rep Power
    0

    Exclamation 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.
    Your change is:
    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. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,903
    Rep Power
    25

    Default 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. #3
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default 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. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,786
    Blog Entries
    7
    Rep Power
    21

    Default Re: Making Change

    Quote Originally Posted by Norm View Post
    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 ;-)
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,903
    Rep Power
    25

    Default Re: Making Change

    How I hated the 2.5 guilders.

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,786
    Blog Entries
    7
    Rep Power
    21

    Default Re: Making Change

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

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,903
    Rep Power
    25

    Default 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. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,786
    Blog Entries
    7
    Rep Power
    21

    Default Re: Making Change

    Quote Originally Posted by Norm View Post
    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
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Replies: 1
    Last Post: 04-17-2011, 04:59 PM
  2. making an exe from .jar
    By ron2794 in forum NetBeans
    Replies: 3
    Last Post: 02-04-2011, 09:28 AM
  3. Need help making a GUI
    By DrKilljoy in forum New To Java
    Replies: 21
    Last Post: 07-15-2010, 04:44 AM
  4. Need help making .jar
    By yoodidoo in forum Eclipse
    Replies: 4
    Last Post: 08-03-2009, 09:57 PM
  5. Replies: 3
    Last Post: 07-15-2009, 07:10 AM

Posting Permissions

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