Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

storing user input in an array

 
Katie Tuffrey
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so i have a few classes:
GuiMain
StudentProfileDisplayGui
StudentProfileEditGui
Students

im not sure the best way to go about creating my array...
i want to store input that the user enters in the StudentProfileEditGui into an array, either in the student class or in the StudentProfileEditGui.

i know how an array works + the basic syntax but really not sure how to go about it, ive tried it in my StudentProfileEditGui and it throws up numerous errors.


this is my students class:


i will post my other if needed
x
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Katie Tuffrey wrote:...ive tried it in my StudentProfileEditGui and it throws up numerous errors...

Please post what you've tried and the errors you encountered.
 
Winston Gutkowski
Bartender
Pie
Posts: 10504
64
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Katie Tuffrey wrote:im not sure the best way to go about creating my array...
i want to store input that the user enters in the StudentProfileEditGui into an array, either in the student class...

No.
And the class you've created is called 'Students' even though it only seems to define a specific Student.

...or in the StudentProfileEditGui.

Definitely not. Keep your GUI completely separate from your data objects.

Try this: Student (in place of your 'Students') for an individual; Students (or possibly a StudentManager) to handle bunches of students; and StudentProfileEditGui (and any other GUI object you think you need) for your GUI stuff.

i know how an array works + the basic syntax but really not sure how to go about it, ive tried it in my StudentProfileEditGui and it throws up numerous errors.

My advice: forget arrays, and learn the Java collections API. An ArrayList is practically an array anyway, but you can do a lot more with it. It may take you a little longer, but you'll be much further along the road when you're done.

Winston
 
Ben Ooms
Ranch Hand
Posts: 47
Debian Eclipse IDE Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also check your student(s) class. Like designed right now if you create two students they will share the properties because you marked them as static. This means that if you do this:


Both Student a and b will have the FullName == "student b "
 
Campbell Ritchie
Sheriff
Pie
Posts: 49789
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ben Ooms is right. I think you need to go back to get your Student class working correctly, without any static members. Only then consider arrays or Lists or whatever.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic