sysc2004
code of student class "sysc2004".
main va Student.java ublic class Main { public static void main(String[] args) { 9 A6 X5 // initialize a new Student object Student s1 = new Student ( name: "James", id: "100010001"); // creating some courses Course course1 = new Course( title: "ML", code: "sysc4906"); Course course2 = new Course( title: "OM", code: "elec4705"); Course course3 = new Course( title: "OOP", code: "sysc2004"); Course course4 = new Course( titie: "C". code: "sysc2006"); Course course5 = new Course( title: "OR", code: "sysc3200"); // adding the student to all these courses s1.addCourse (coursel); s1.addCourse(course2); s1.addCourse (course3); s1.addCourse(course); 1/ add a call to your created accessor method here print out the call to getFullLoad() Il adding the final course s1.addCourse (course5); // add another call to your created accessor method here print out the call to getFullLoad() In the main method we created our Student "James" and added him to some courses. However, there is a problem. There is no accessor method for our fullLoad attribute. Time to add one! Go into the Student class and create a new accessor method called getFullLoad() . Pay attention to your access modifiers and the return type (we want to return the actual value of the field, not print it out). Then back in Main.java , make two calls to your new method to test that it actually works. Run it! Really try it before peeking the solution. import java.util.ArrayList; 1 A8 public class Student { private String name; private String id; private ArrayList
courses private boolean fullLoad; // the student's name // the student's id number // courses the student is enrolled in // does the student have a full course Load? * Create a new student with the supplied attributes. Courses and fullLoad are defaulted to o/false. public Student(String name, String id) { this.name = name; this.id = id; courses = new ArrayList(); fullLoad = false; } Il new empty ArrayList 0 21 22 23 24 /** * Get the fullLoad status of this student. / bike getFullLond() for CO * Get the name of this student. */ public String getNane() { return nane ;) 26 27 30 31 32 33 Compil on Fades * Set the name of this student. */ public void setName(String newName) { name = new Name: Post Sol 01 AB AV Get the id of this student. +/ public String get10() { return id; } /** Set the id of this student. */ public void setID(String newID) { id I newID;) * Add a course to this student's course list. A student can only be enrolled in 5 courses at a time. */ public void addCourse(Course course) { if (!fullLoad) { courses.add(course); if (courses.size() == 5) fullload = true; } * Remove a course from this student's course list. */ public void removeCourse(Course course) { if (courses.remove(course) fullLoad = false; } * Print out the courses field. #/ public void printCourselist() { for (Course c : courses) { System.out.println(c.getTitle() + + c.getCode()); public class Course { 1.5. Stude private final String title; private final String code; private int numberOfStudents; // title of the course // course code // the number of students enrolled /** * Creates a new course with the supplied attributes. The number of students is by default 8. public Course(String title, String code) { this.title = title; this.code = code; numberOfStudents = 0; /** * Get this course's S code, 3 public String getCode() { return code; } - * Get this course's title. */ public String getTitle() { return title; } 3 /** * Increments the number of enrolled students. Returns the new number of enrolled students. */ public int addNewStudent() { number of Students += 1; return numberOfStudents; }