This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Well, the problem is the same one in my thread "problem with StringBuffer and Double," which is a bit more complex, but I am thinking that this is the kind of problem. The code in that thread compiles and runs, but it doesn't print the individual employees' gross and net amount, though it does print the exactl total for all employees. I just thought that my code (above) might be simpler to try and work with.
Indeed, the variables need to be static, but I think you know that. This program will act in a potentially surprising way because although methodOne() assigns a value to the parameter "z", the member variable "z" remains unchanged. The parameter "z" and the member variable "z" are completely unrelated, and perhaps that's the root of the problems you're having.
There are several practices here that are bad habits, and perhaps I should just point them out. One is naming local variables or parameters the same as member variables. Although this isn't technically wrong, it's always confusing and there's rarely an excuse for doing it. In this program I suspect that fact that you're reusing names is confusing you.
Another thing that's generally bad (although this one is more subtle) is writing methods which are useful only for their side effects. If you have a choice between writing
and then calling it as "c = method(1, 2)", the second choice is generally preferred. There are many reasons for this, but the two most important are that it makes it more obvious what the method does, and that it makes the method easier to test in isolation. Methods whose explicit purpose is to set a variable are OK, by the way. That's why I said this point is subtle; it's a judgement call.
I'm getting "cannot find symbol" in processPay() and printEmployeeInfo()
I am lost in this code...
Joined: Feb 03, 2005
here is my latest idea. the method processPay() internally sets the value of the two Doubles in question. what's wrong with the way I'm doing this? I'm so befuddled I don't know what else to ask/try/say...