• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

parameter passing (very beginner)

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Brian Rush
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1056
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
He's my best friend. Not yours. Mine. You can have this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic