Results 1 to 4 of 4
Thread: help me a bit tough
- 06-26-2010, 05:39 AM #1
Member
- Join Date
- Jun 2010
- Posts
- 4
- Rep Power
- 0
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
-
- 06-26-2010, 02:01 PM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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 :)
- 06-26-2010, 02:14 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,375
- Blog Entries
- 7
- Rep Power
- 17
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,
Jos
Similar Threads
-
Really tough question
By tranceslave in forum Java 2DReplies: 3Last Post: 02-03-2010, 12:54 AM -
Really Really Tough Bug in JSP
By ajt111 in forum JavaServer Faces (JSF)Replies: 1Last Post: 10-28-2009, 05:49 PM -
Tough Homework Questions, PLEASE HELP!
By passage in forum New To JavaReplies: 21Last Post: 01-16-2008, 11:04 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks