Answered step by step
Verified Expert Solution
Question
1 Approved Answer
public class Instructor { private String name; private String department; private boolean tenure; private int numStudents = 0; public Instructor(String name, String department, boolean tenure)
public class Instructor { private String name; private String department; private boolean tenure; private int numStudents = 0; public Instructor(String name, String department, boolean tenure) { this.name = name; this.department = department; this.tenure = tenure; } public String getName() { return name; } public String getDepartment() { return department; } public boolean getTenure() { return tenure; } public int getNumStudents() { return numStudents; } public void setTenure(boolean newValue) { tenure = newValue; } public boolean assignNewCourse(int numNewStudents) { if (numStudents + numNewStudents > 500) { return false; } numStudents += numNewStudents; return true; } }
public class Course { private final String title; // title of the course private final String code; // course code private int numberOfStudents = 0; // the number of students enrolled private String instructor = ""; // the name of the instructor of the course /** * Creates a new course with the supplied attributes. The number of students is by default 0. */ public Course(String title, String code) { this.title = title; this.code = code; } /** * Get this course's code. */ public String getCode() { return code; } /** * Get this course's title. */ public String getTitle() { return title; } /** * Increments the number of enrolled students. */ public void addNewStudent() { numberOfStudents += 1; } /** * Get the instructor of this course. */ public String getInstructor() { return instructor; } /** * Set the instructor of this course. */ public void setInstructor(String newInstructor) { instructor = newInstructor; } }Our completed Instructor.java file from Lab 1 is included here. We are going to be making some modifications. Make the following changes to Instructor.java: Create a new field called courses to store all of the Courses currently being taught by this Instructor. You decide what type it should be (make a logical decision, there is a mark for this). We also want to transform the numStudents field into an ArrayList of students. This ArrayList will contain all of the Students that the Instructor is currently teaching. This means you must update the assignNewCourse () method. o The method should now take a Course object as a parameter. o The method should add the new Course to the courses field. Note that you cannot assign the Course to the Instructor if the Instructor is already assigned the Course (there is a Course with the same code in courses ). o If the Course is added to courses ourses , it should also take all the students enrolled in the Course and add them to the students ArrayList in Instructor (you will need an accessor method!). You can assume that there are no duplicate students when writing your assignNewCourse () method. o The previous functionality should remain the same, i.e. the Instructor cannot be assigned a new Course if the new Course brings the total number of students to over 500. The method should still return a boolean based on whether or not the assigning was successful. o If the assigning is successful, set the instructor field for the Course to that Instructor (Note: this is tricky). You will also need to modify the respective fields/methods in Course.java so that an Instructor object is used instead of a String. The default value of instructor should be null. We still want a getNumStudents () method in Instructor.java . Make the required modifications so that the number of students the Instructor has is returned. Do not re-add the old numStudents field, you do not need another field
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started