public void printClassList() { System.out.println("Teacher: " + teacher.getName()); System.out.println("Subject: " + teacher.getSubject()); System.out.println("Students:"); for (String s : students) { System.out.println("- " + s); } } } Alex writes a Main class to test his system:
public boolean addStudent(String studentName) { if (students.size() < teacher.getMaxClassSize()) { students.add(studentName); return true; } return false; } 7.2.8 Teacher Class List BEST
compSci.printClassList(); System.out.println("Added Alex? " + added); } } When Ms. Chen runs the program, she sees: public void printClassList() { System
public class Main { public static void main(String[] args) { Teacher chen = new Teacher("Ms. Chen", "AP CSA", 5); ClassList compSci = new ClassList(chen); compSci.addStudent("Maya"); compSci.addStudent("Jordan"); compSci.addStudent("Sam"); compSci.addStudent("Taylor"); compSci.addStudent("Casey"); boolean added = compSci.addStudent("Alex"); // Should fail — max size 5 System.out.println("Subject: " + teacher.getSubject())
public ClassList(Teacher teacher) { this.teacher = teacher; this.students = new ArrayList<>(); }