• Post Reply Bookmark Topic Watch Topic
  • New Topic

Input into a method  RSS feed

 
Aaron Rudd
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello I am trying to use an input from a different method into the next method to have the system output the users name. Any help would be appreciated thank you  [
 
Norman Radder
Ranch Hand
Posts: 146
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
input from a different method into the next method 

What are the names of the methods you are having problems with?
 
Aaron Rudd
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to get the input of the sales persons name to print into where I ask for the annual salary.  From there I am working to then have the system ask for the second sales person salary.
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I suggest you create a smaller class with one variable which you read from the keyboard with a Scanner. Once you are happy you have got that working, consider scaling it up to multiple fields.
Also, factor all reading from the keyboard into separate methods. In fact it is better to put that in a separate class. I haven't got the time to go through any details, but start by searching my posts for Scanner hasNextInt. You will find a technique which Rob Spoor taught me to avoid having to bother with Exceptions from a Scanner pointing to System.in. Only it will be in bits which require assembly. Batteries not included.
 
Knute Snortum
Sheriff
Posts: 4281
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aaron Rudd wrote:I am trying to get the input of the sales persons name to print into where I ask for the annual salary.  From there I am working to then have the system ask for the second sales person salary.

One way to do this is to declare String[] name outside of any methods, like you've done with several other variables.  This would made name visible in all methods -- maybe not what you want.

Another way is to return the name array from the salesPerson method and pass it into the getSales method as a parameter.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!