Question: Enable the Course class cloneable. Rewrite the Course class to add a clone method to perform a deep copy on the students field. Write a

Enable the Course class cloneable. Rewrite the Course class to add a clone method to perform a deep copy on the students field. Write a test program that creates a course, populates it with 5 students (with the following names: Eddie Woodward, Tiana Hopkins, Ariel Ortiz, Tanner Rubio, and Aubree Mccall), clones the object, and prints whether the two students fields point to the same array (i.e., it should print false) .

public class Course {

private String courseName;

private String[] students = new String[4];

private int numberOfStudents;

public Course(String courseName) {

this.courseName = courseName;

}

public void addStudent(String student) {

students[numberOfStudents] = student;

numberOfStudents++;

}

public String[] getStudents() {

return students;

}

public int getNumberOfStudents() {

return numberOfStudents;

}

public String getCourseName() {

return courseName;

}

public void dropStudent(String student) {

// Left as an exercise in Exercise 10.9

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!