Keith Lynn wrote:Are you sure the .class file of your program is in the CLASSPATH and that the class has a main method?
Stefan Evans wrote:
It shouldn't be saved in sum?
Correct. If what you are calculating is the federal tax, then it should be saved into the variable for federal tax.
And then on the next line where you print it out, it will print out the correct value.
The reason it is printing 0 right now, is that you did the calculation for it BEFORE the user entered in the data.
I actually don't understand what the "sum" variable represents.
All of the other variables are named well, but this one is a mystery to me.
Do you need it? What does it represent? Maybe you can name it better?
Also note that you have two variables:
Sum with a capital S and sum with a lower case s. That also caused me some confusion.
Liutauras Vilda wrote:Here is what you have at the moment:
As you see at the beginning you initialize "salary", "numDependents", "sum" with 0 (it is fine so far).
Then, on the lines below you do some calculations and assign variables with results.
So, "dependentDeduction", "stateTax", "federalTax", "totalWithholding", "takeHomePay" you get 0 too (not what you want).
The point is, that you using those variables mentioned two lines above in your later calculations and you get I believe not what you think you should get.
Stefan Evans wrote:Ok, when I run it I just see a bunch of $0 printed out.
Here is a snippet of some of your code:
I read this code as:
multiply salary by the federal tax rate, and save it in the variable "sum"
print out the value of the variable "federal tax"
When I put it like that, do you see any problems with it?
Campbell Ritchie wrote:
You don't need to parse anything in what you wrote. There are two reasons it won't work (probably more):-Enos Winder wrote:. . .
Now on the last line you will need a parse.
. . .1: You are trying to sort out somebody else's code and only correcting part of it. 2: You have salary uninitialised. When you get to the next line, the compiler thinks, “how much is salary? I don't know,” and won't compile any more. If you can get input via Scanner, use Scanner.
EW: option pane is a very old‑fashioned programming style. It is probably a bad idea to mix console input and GUI input anyway. You seem to be confusing OS by adding things she is unfamiliar with.
Enos Winder wrote:Ok, If I have a piece of code that looks like this:
I can make this same code look like this:
Or, I can use JOptionPane to do this:
This is what I mean when I say replace