• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Input into a method

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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  [
 
Ranch Hand
Posts: 146
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79240
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic