Seetharaman Venkatasamy wrote:money calculations on double is dangerous!
Not the faintest idea where you will find anything at all, but if you are really desperate you can try here. Or click the words in your post which have been underlined; they turn into links automatically.Jason Smit wrote: . . . Can you please point me in the right direction where to get information about BigDecimal,
In which case this will be of no use to youand also the equivalent to NextDouble (when prompting the user)
Checked out the net and I saw so much information...very little on an equivalent to NextDouble...
Campbell Ritchie wrote:
Not the faintest idea where you will find anything at all, but if you are really desperate you can try here. Or click the words in your post which have been underlined; they turn into links automatically.Jason Smit wrote: . . . Can you please point me in the right direction where to get information about BigDecimal,
In which case this will be of no use to youand also the equivalent to NextDouble (when prompting the user)
Checked out the net and I saw so much information...very little on an equivalent to NextDouble...
That phrase should strike terror and loathing into your heart. It makes it sound as if you were guessing.Jason Smit wrote:another try... . . .
Campbell Ritchie wrote:Sorry, I misread your code badly and misinterpreted some bits. Please ignore what I
struck outin the previous post. I am very sorry about that mistake.
Alternative to NumberForma: the printf method or String#format. You would want something like $%.2f to get money into dollar format. I think that rounds ¢0.5 up to ¢1, but I am not certain. Look in the java.util.Formatter class for details of the % tags, also look in the Java Tutorials.
Campbell Ritchie wrote:You ought to have created a Pay class and had several instance of it, rather than deleting the information every time you have a new pay rate.
Jason Smit wrote:Can you please tell me if I am leaving anything out of the program?...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Jason Smit wrote:This is where I begin to start pulling my hair...like I said...I am a newbie.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Jason Smit wrote:This is where I begin to start pulling my hair...like I said...I am a newbie.
Not quite sure what your problem is now, but you should definitely follow Dennis' advice and break up some of those huge calls. I would also get into the habit of writing methods that take arguments and return values; it makes them more self-contained (Google "loose coupling").
For example:and then you can call it from elsewhere with something like:
BigDecimal pay = calcPay(hoursWorked, payPerHour);
It may seem like more code, but do you see how much clearer it is?
The above is by no means the only way of doing it, I just provide it as an example.
HIH
Winston
sorry for delay; I have been busy, and didn’t understand the problem yesterday.Jason Smit wrote: . . . . My point is why does your example return just "wages" when the parameters include BigDecimal hours and BigDecimal payRate. Should it not return "hours" and "payRate"?
Jason Smit wrote:I am not how to call this method (i.e. CalcPay)? Any advice where I am going wrong??
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Jason Smit wrote:I am not how to call this method (i.e. CalcPay)? Any advice where I am going wrong??
Well, first: it should be calcPay(), not CalcPay(). It's only a convention, but it's very widely used (and often required by companies), so I'd get into the habit if I were you.
Second: You seem to be concentrating far too much on language minutiae rather than thinking about what you're class is supposed to be doing.
My advice:
1. Turn your computer OFF.
2. Write down in English, what you want your class to do.
3. (Only when you have written and understand exactly what is needed) turn your computer back on and refactor your class accordingly.
I know it's a great temptation, but jumping straight into Java code is usually a very bad way to go. Make sure you understand the problem (or the requirements) before you write a line of code.
Winston
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |