[My Blog]
All roads lead to JavaRanch
Stephan van Hulst wrote:I also prefer to leave them out completely if the conditional statement is simple.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Bad pun alert!Rob Spoor wrote: . . . Which will byte you in the behind . . .
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Ben David wrote:I am guessing there is probably no easy thing you can tell someone about how to approach a problem to come up with elegant algorithms like this, but just curious if there are pointers you can give.
How to originally approach/think about a the problem.
How to tell when you are making it harder than it needs to be, etc.
Are there any books you might recommend that teach this sort of thing.
The only problem I found with this, is that if there is one hundred or one thousand, etc -- it leaves out the "one" part, and just puts "hundred".
Below is my fix for this. I am just curious. Would you have had an even simpler more elegant fix?
And to make this do the full thing of saying integer, as well as the first two decimal places, I would probably, in the main method, just call it on the decimal, then subtract the rounded down decimal from itself (to get just the decimal part) and multiply by 100, and then give that the convert to get the two digits after the decimal.
(And also just add the "dollars" and "cents" in the main method. Is that probably the easiest way, or would you have a more elegant solution for that up your sleeve?
Ben David wrote:Are there any books you might recommend that teach this sort of thing.
p.s. @Christophe -- the exceptions are just thrown in places, that I never wanted to reach in the code, and where eclipse was requesting I put a return value. So I just threw a generic exception, so I would know where to investigate. Is this a bad use of that? Is there a better approach I could have taken to the situation?
[My Blog]
All roads lead to JavaRanch
Don't get me started about those stupid light bulbs. |