File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
    Bookmark Topic Watch Topic
  • New Topic

Passing Objects Created By User to Array in Different Class

 
Kd Martin
Ranch Hand
Posts: 59
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
I have to create two classes: Student and Course. The purpose of the program is to have the user create students and courses and add students and drop them from courses. I was told by my professor to create an array called "Student" in the course class. What I'm having a problem understanding is how to pass the student object created by the user in the class "EnrollStudent" to "Course" to fill the array "Student". If you could help me understand this I would really appreciate it! Thanks!

Student:


Course:


Enroll Student:
 
Joanne Neal
Rancher
Pie
Posts: 3742
16
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
First I assume you are getting at least one compilation error for your Course class. The addStudent method should not be static.
Once you've fixed that you will need to call that method to add a student to the course.

The first thing you need to do is find out which course the student is to be enrolled on. Lets assume for the moment it's only going to be one course - we can expand it later to support multiple courses.
Probably the easiest way to do this is to display a numbered list of courses and ask the user to enter the number of the course.
Give that a go and see how far you get. You'll need a for loop to display the list and it needs to go after line 39 where you create the Student object.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47300
52
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
Sorry, I forgot to welcome you to the Ranch. Welcome, now

This question looks so similar to your question from yesterday that I shall close this thread; please continue discussion there (even if I did scare you with a long reply there).
 
I agree. Here's the link: http://aspose.com/file-tools
    Bookmark Topic Watch Topic
  • New Topic