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
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