i understand the difference and i know how to call them but for some reason my printResults is not working. the whole point is to figure out how much the tax rate in getTax() then figure it out how much tax is owed in main and print it out in printResults() i can get the name to print just not the taxOwed
this is an assignment for a class i have but if anyone could give me any hints about what i am doing wrong it would be greatly appreciated
When you call your getTax method, you send the tax variable which has been initialized to 0 and then never changed. Why are you doing that? If you are not going to manipulate the tax variable before you do a call, write the getTax method to take no parameters. Or better yet, put the read from system.in up in the main method and then send the information to the getTax method. Then when you call the getTax method with the meaningless parameter, you do it in a print call, but never CAPTURE the value that was returned. I expect that you do not realize that the tax variable in the getTax method is local to that method, so the main method can not read it. The tax variable in the main method is a DIFFERENT variable which is never set. You could either capture the returned value double tax = getTax(); System.out.println(tax); or you could create a static variable above the main method, and be sure that it does not get covered up by any local variables with the same name. Do not declare the variable in the method, just use the member variable. In your print results method you are shoving your input variables into OTHER variables for no good reason. Just use the input variable names in the print statement.
Hi Pam, A few things come to mind. 1. You should place all user I/O calls into a single method. Either inside main or create another method. 2. As Cindy pointed out you are using a lot of local variables that are not required. 3. It is always a good idea to output everything that was input when dealing with console input. Therefore I would send more parameters into the printResults method. 4. Not sure if you learned about try/catch yet. But I would rather put the try/catch for the I/O error inside the main method. Also I would catch a bad input (especially for the income as long!). 5. Not sure if you know about java.text.Decimal format yet either. But I like formatting outputs! The program might look something like that below.