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 parameter passing (very beginner) 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 "parameter passing (very beginner)" Watch "parameter passing (very beginner)" New topic
Author

parameter passing (very beginner)

Brian Rush
Greenhorn

Joined: Nov 10, 2002
Posts: 2
Hi,
I'm trying to get the variable qty that was returned from the getUserInput method passed into the computeTotals method. It doesn't see the var qty being passed in. What am I doing wrong here? TIA!
Brian
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
This doesn't compile. I get these errors:
tvBill3.java:17: cannot resolve symbol
symbol : variable qty
location: class tvBill3
computeTotals(qty);
^
tvBill3.java:45: cannot resolve symbol
symbol : variable qty
location: class tvBill3
double [] extension = new double [qty.length];
^
tvBill3.java:48: cannot resolve symbol
symbol : variable qty
location: class tvBill3
for(int i=0; i<qty.length; i++)
^
tvBill3.java:50: cannot resolve symbol
symbol : variable qty
location: class tvBill3
extension[i] = qty[i] * price[i];
^
Are you sure that you posted the exact source code that you are running?


Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Brian Rush
Greenhorn

Joined: Nov 10, 2002
Posts: 2
Those are the errors I get as well. The caret is pointing to the qty variable in each error. This is where my problem lies. I thought qty was returned back to the main method. Then it gets passed to the computeTotals method as a parameter. It is not being seen in the computeTotals method.
Thanks,
Brian
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
You are referring to a variable called "qty" in your main() method, but there is no such variable declared in either the tvBill3 object or in the main() method.
You are calling computeTotals() with a "qty" parameter, but you have declared this method to take no arguments. You're also referring to "qty" inside the function, but you haven't declared it as either a variable or a parameter.
Richard de Boer
Greenhorn

Joined: Nov 11, 2002
Posts: 4
Originally posted by Brian Rush:
[QB]Hi,
I'm trying to get the variable qty that was returned from the getUserInput method passed into the computeTotals method. It doesn't see the var qty being passed in. What am I doing wrong here? TIA!
Brian
Good morning Brian,
In java a variable lives between the enclosing {}.
So you cannot ask for it outside the brackets.
There is a way around that called a return type. This is what you used in the correct way.
But when something is returned it loses it's name. So you have to store it again. And you are free to choose a new name!!!
A compile-able version of your code:

Enjoy java,
Richard
(edited by Cindy to format code . . . hint, hint)
[ November 18, 2002: Message edited by: Cindy Glass ]
Sam Zou
Ranch Hand

Joined: Nov 18, 2002
Posts: 40
Hi !

I'd like to known if this line works !
String input = javax.swing.JOptionPane.showInputDialog("How many " + howManyCategory[i] + " were sold?");
I try it and nothing happened ! The program just hang.

By the way, here is a working version of your program but without the Swing dialog box.

Thanks
[ edited to surround code with the [code] and [/code] UBB Tags so as to help preserve formatting and make the code easier to read -ds ]
[ November 18, 2002: Message edited by: Dirk Schreckmann ]

Sam<p>"Life is difficult"<br /> -Scott Peck-</p>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: parameter passing (very beginner)
 
Similar Threads
How can I debug it ?
values changed, math didnt.
Event-handling Problem in 3-JComboBox and 1-JTable Search Program
How can I debug it ?
values changed, math didnt.