Reputation: 385
I am trying to add an association between Course class and Lecturer class, but I am getting an error.What am I doing wrong?
I am adding this piece of code into the Course class so that for each course a cordinator is assigned.
public void addCordinator(Lecturer newLecturer){
this.lecturer.add(newLecturer);
}
Upvotes: 0
Views: 320
Reputation: 5334
Im not sure how your application looks like, but if you have one class called Course, and one called Lecturer and you want to make it possible for a course to have one or more lecturers, you can have a arraylist<Lecturer>
inside the Course class. It would look something like this:
public Class Course{
List<Lecturer> lecturerCollection= new ArrayList<Lecturer>();
//this method will be called with a lecturer object
public void addCordinator(Lecturer newLecturer){
lecturerCollection.add(newLecturer);
}
so you are now able to store lecturers for each corse, so if you have a Course object named course1, you can simply call course1.addCordinator()
to add one or more lecturers to each course.
This is as much as I can help you with the current code you provided
Upvotes: 2