Os Stewart

Ranch Hand
+ Follow
since Feb 02, 2014
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Os Stewart

Keith Lynn wrote:Are you sure the .class file of your program is in the CLASSPATH and that the class has a main method?



I think so, The file works for me, but when my friend tries it, it does not work.

9 years ago
Can someone let me know what I can do to fix the error:

Error: Could not find or load main class

9 years ago

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.



Okay, the sum is suppose to be the salary and dependents multiplied total.
9 years ago

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.



So how do I fix it? My original code the, the variables I did not add the "= 0" to, and it did not work at all. I don't know how to fix the variables, that is my problem.
9 years ago

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?



It shouldn't be saved in sum?
9 years ago
I don't get any of this. I don't understand what to do to fix it or how. I know where it's going wrong, but I don't get how. I need to step away from looking at this, because my brain is not understanding this right now.
9 years ago



And there are no errors anymore, but I can't get the salary and dependents to give me a sum. And the State Tax, Federal Tax, Withholdings, and home pay won't generate either. I'm lost. I'm just trying to get this too work to see what the final result will look like.

When I run it, this is what I get:

run:
Enter Employee name: ofelia
Enter Salary: 1500
Enter number of dependents: 2
false
State Tax: $0.0
Federal Tax: $0.0
Total Withholdings: $0.0
Take Home Pay: $0.0
BUILD SUCCESSFUL (total time: 35 seconds)
9 years ago
I thought I had it but I don't. My values are the Salary and number of dependents. I thought?
9 years ago
the printIn (sum) reads false?
9 years ago
Okay, when I compiled it everything inputted fine, but it won't compile the sum of any of the math. Am I missing something here? My math looks right, but it won't total it?

9 years ago

Campbell Ritchie wrote:

Enos Winder wrote:. . .
Now on the last line you will need a parse.
. . .

You don't need to parse anything in what you wrote. There are two reasons it won't work (probably more):-
  • 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.





    Okay, when I started, this code was a mess. I got it from an old text book when I was in school. The lesson was to make it compile and fix the errors. I fixed the error, and the next lesson was to be able to input Salary and the number of Dependents. So I came up with this.



    My issue that I was having that was that the Salary and Number of Dependents are coming up with the errors, that they "might not have been initialized."

    I'm just trying to go on lesson by lesson to try to familiarize myself with the steps to "do the job", sort of speak. As the studies in the book go, more things will be added and so on.
    9 years ago
    I'm sorry you guys... I'm lost, I'm going to start from the last code with Scanner, and try to work from there. I'm not trying to make a pop up box right now, I'm just trying to understand the "Simple stuff" first. I'm sorry you guys, I'm trying to learn, but unfortunately it's a lot to take in for someone who hasn't done this much before. :-)
    9 years ago
    Line 18 says that my salary and numDependents might not have been initialized.
    9 years ago
    Ok this is what I did:



    I can not get it to work. My salary and numDependents is still not working. Same errors as before. I've never used this JOptionPane before, so I don't know what to do. I'm just trying to get it to calculate my input from salary and dependents.
    9 years ago

    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



    Okay, let me try this...
    9 years ago