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
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Passing Objects Created By User to Array in Different Class

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 80962
526
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
What kind of corn soldier are you? And don't say "kernel" - that's only for this tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
    Bookmark Topic Watch Topic
  • New Topic