This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes procedures and functions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "procedures and functions" Watch "procedures and functions" New topic
Author

procedures and functions

pam rowell
Greenhorn

Joined: Jan 21, 2002
Posts: 7
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
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
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.
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
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.

Regards,
Manfred.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: procedures and functions
 
Similar Threads
Help with english to morse code program, I have no idea what I'm doing
Incompatible types error
Try and catch Help!
urgent help needed for assignment
Class Help!