• Post Reply Bookmark Topic Watch Topic
  • New Topic

Arrays of Objects 2!  RSS feed

 
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to two of you who responded to my last question, I was able to succesfully create an array of student objects.

However, I am having a problem passing it to another class.

I have two classes you see....

StudentApp.java - this creates the array and inputs data into it

Student.java - this manipulates student objects.

What I want to to is pass the studentArray from the StudentApp.java class (whic contains the main method) to the Student.java class so that I can search through it. Im not sure how to do it as It wont recognise that array in the Student class.

Can you please help?

Thanks
[ October 25, 2006: Message edited by: Sam Bluesman ]
 
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post the error message?
 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I want to to is pass the studentArray from the StudentApp.java class (whic contains the main method) to the Student.java class

Bad idea. There is nothing inherent in the concept of a Student that would require it to know how it was arranged with other Students.

so that I can search through it

Search through it in main(), or write a method for searching through it and put the method in StudentApp.java, and call the method from main(). Or, create another class called StudentGroup whose constructor creates an array of Students. Then add methods to StudentGroup that allow you to search through the group. Inside main() in StudentApp.java, you can create a StudentGroup and then call its search methods.
[ October 25, 2006: Message edited by: sven studde ]
 
Sam Bluesman
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error message just says that it can not find the variable. I have been asked to program this way and personally i think it's really bad, hence i;ve never done it this way...
 
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sam Bluesman:
... What I want to to is pass the studentArray from the StudentApp.java class (whic contains the main method) to the Student.java class so that I can search through it...

I'm a little confused about how this is set up. Is the Student class going to have an array of Student instances?

Can you show us some of the code you've tried?
 
Sam Bluesman
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actaully maybe my question should bne this:

Lets say I have to type in the number of students i want (thus giving the length of the student object array). The code for recieving this input is in the StudentApp.java class.

Would you populate the array in this class, or would you populate the array in the Student.java class (which contains methods for calculating overall % marks of each student, etc). At the moment, the array is being populated in the StudentApp.java class.

Good idea or not?

Thanks
 
Sam Bluesman
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by marc weber:

Is the Student class going to have an array of Student instances?

Can you show us some of the code you've tried?


At the moment the StudentApp.java class has the array. I want to pass it over to the Student.java class for processing...

Thanks
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sam Bluesman:
...At the moment, the array is being populated in the StudentApp.java class.

Good idea or not? ...

That makes sense. A StudentApp works with Student objects, so it "has" Students to work with (in an array). I don't see any sense in a Student "having" other Students.
 
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Show us your source code that has the error and copy & paste the error message here, it's a bit difficult to tell you what the problem might be with a blindfold on... :roll:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!