I have Course class
public class Course implements Comparable<Course > {
private String nazwa;
private Integer lata;
private Teacher teacher;
private Student[] students;
public Course (String name, int years, int maxStudents, Teacher teacher) {
this.name = name;
this.years = years;
students = new Student[maxStudents];
this.teacher = teacher;
}
I'm not sure if it's proper way to do it
public void setTeacher(Teacher teacher)
{
this.teacher = teacher;
}
Then I have some code that allow user to create new Course. I first ask for some basic informations
System.out.print("ask for name");
String name= scan.next();
System.out.print("ask for years");
int years= scan.nextInt();
System.out.print("ask for maxStudents");
int maxStudents = scan.nextInt();
There is my try to add teacher to new course. Teacher have unique ID
Course course;
System.out.print("Choose teacher:\n");
teachers is a list, that containts all teachers
for(Teacher t : teachers)
{
System.out.print(t.getName() + " - " + t.getAcademicDeggre() +"\n");
}
course.setTeacher(Teacher ?);
courses.add(new Course(name, years, maxStudents, teacher?);
@Solution:
int choice= scan.nextInt() - 1;
String ID= teachers.get(choice).getID();
Teacher teacher = getTeacherForCourse(teachers, ID);