Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Carey Brown
  • Frits Walraven

How to assign scanner inputs as next values of instance variables of an object array

Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello. I'm not sure if I'm titling my question correctly cause I am still trying to understand the many terminologies.

I'm trying to make a Student Registry program wherein the user gets to input several names which gets stored to student[i].name such that when the user input "John", it gets stored to student[0].name and then when the user inputs again another name such as "Sandra", it gets stored as student[1].name, and so on and so forth.  I have tried several times to no avail.

I'm not asking for the exact code per se (as I still want to learn by doing) but maybe just the process to how I'm going to accomplish what I'm trying to do.

I didn't know this "challenge" would take too much of my time. Thus, the reason I'm here at this forum at this point. Hahaha. Many thanks in advance!
Posts: 4545
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

jerome sagcal wrote:I have tried several times to no avail.

These attempts (or just the one you think is best) would help us understand what issues you are having with this.
Posts: 68899
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Please provide us with more details, for example, where are you taking input from? Why have you got a non‑private field like name? Why aren't you setting the name via a constructor?

Have you been through the methods of Scanner, particularly those with names like nextXXX()?
I guess I've been abducted by space aliens. So unprofessional. They tried to probe me with this tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
    Bookmark Topic Watch Topic
  • New Topic