The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

First, simple, two-classed tax program

Hi all,

I'm entering into a programming course next September and am trying to get the essentials of Java before hand. I attempted to create my first program but have learned that it's much easier when you can speak to someone who knows what they're doing. Anyway, here is my code:

Second, I'm not sure where your stateTax variable is coming from. I can't find where it is declared. Please look at my signature and click the link for the java tutorials. I would go through them all, but pay special attention to primitive data types as well as defining classes.

Second, I'm not sure where your stateTax variable is coming from. I can't find where it is declared. Please look at my signature and click the link for the java tutorials. I would go through them all, but pay special attention to primitive data types as well as defining classes.

Re: First, simple, two-classed tax program

If you get errors, please post the full error message text and stack trace (if present). Java errors usually tell you exactly what is wrong and where.

To create a new instance of Taxone, you must use the 'new' keyword:

Taxone t = new Taxone();

I can see you appear to be trying to declare a public double in the middle of your 'main' method, but not only can you not do that (only member variables can have access specifiers like 'public', not local variables) it doesn't make sense, because you haven't named it:

...public double ?? t.calctax(); // ?? where's the variable name?
...

You're also using local variables 'stateTax' & 'income' that you haven't declared, and calling a method 'calctax()' that doesn't exist, you're trying to return a value from 'main', which is a void method, plus you have a curly brace { that has no corresponding closing curly brace }, state value or variable NY is undefined (it could be "NY"), etc...