У меня есть курс курса
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;
}
Я не уверен, если это правильный способ сделать это
public void setTeacher(Teacher teacher)
{
this.teacher = teacher;
}
Тогда у меня есть некоторый код, который позволяет пользователю создавать новый курс.Сначала я спрашиваю некоторые основные сведения
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();
Я пытаюсь добавить учителя в новый курс.У учителя есть уникальный идентификатор
Course course;
System.out.print("Choose teacher:\n");
учителя - список, в котором содержатся все учителя
for(Teacher t : teachers)
{
System.out.print(t.getName() + " - " + t.getAcademicDeggre() +"\n");
}
course.setTeacher(Teacher ?);
courses.add(new Course(name, years, maxStudents, teacher?);
@ Решение:
int choice= scan.nextInt() - 1;
String ID= teachers.get(choice).getID();
Teacher teacher = getTeacherForCourse(teachers, ID);