Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2010
    Rep Power

    Default help me a bit tough

    Java Code:
    public class BetterProgrammerTask {
        public static Change getCorrectChange(int cents) {
             [COLOR="Black"][B][U] Please implement this method to
              take cents as a parameter
              and return an equal amount in dollars and coins using the minimum number of
              coins possible.
              For example: 164 cents = 1 dollar, 2 quarters, 1 dime and 4 cents.
              Return null if the parameter is negative.[/U][/B][/COLOR]
        // Please do not change this class
        static class Change {
            private final int _dollars;
            private final int _quarters; //25 cents
            private final int _dimes; // 10 cents
            private final int _nickels; // 5 cents
            private final int _cents; // 1 cent
            public Change(int dollars, int quarters, int dimes, int nickels, int cents) {
                _dollars = dollars;
                _quarters = quarters;
                _dimes = dimes;
                _nickels = nickels;
                _cents = cents;
            public int getDollars() {
                return _dollars;
            public int getQuarters() {
                return _quarters;
            public int getDimes() {
                return _dimes;
            public int getNickels() {
                return _nickels;
            public int getCents() {
                return _cents;
    Last edited by Eranga; 06-26-2010 at 01:56 PM. Reason: code tags added

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Colombo, Sri Lanka
    Blog Entries
    Rep Power


    Please use the code tags also, next time when you are posting code. Unformated codes are really hard to read. If you don't know how to do it, please check on my signature as well as on Fubarables' signature. You can relevant on FAQ as well. :)

    And also please ask your question more clearly. I'm not clear what you are really want to know here. Please use an appropriate title next time.

    pavankumar2215, I'm not trying to discourage you to ask questions here. But those small things make a big difference on your way. Honestly I want to help you, with your commitment. Good luck :)

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Voorschoten, the Netherlands
    Blog Entries
    Rep Power


    Monetary units are designed such that if you use your largest coin as much as possible you have reduced your problem unless there is 0 left and you have solved your problem; the solution is the least amount of coins needed to make the amount of money you started with.

    A coin system that doesn't have this propery is, e.g., 1, 7, 12; you can make 28 by using 4x7; if you follow the rule described above you'd end up with 2x12+4x1 which isn't optimal.

    The 1, 2, 5 system (e.g. US dollars) needs less coins than, say, the old Dutch guilder system which was 1, 2 1/2, 5.

    Anyway, use the rule I outlined above to solve your problem and take the cent as your monetary unit.

    kind regards,


Similar Threads

  1. Really tough question
    By tranceslave in forum Java 2D
    Replies: 3
    Last Post: 02-03-2010, 12:54 AM
  2. Really Really Tough Bug in JSP
    By ajt111 in forum JavaServer Faces (JSF)
    Replies: 1
    Last Post: 10-28-2009, 05:49 PM
  3. Tough Homework Questions, PLEASE HELP!
    By passage in forum New To Java
    Replies: 21
    Last Post: 01-16-2008, 11:04 PM

Posting Permissions

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