Question: Please dont post the answer as a pdf file, thank you! Programming Exercise 13.13 Rewrite the Course class in Listing 10.6 to add a clone
Programming Exercise 13.13 Rewrite the Course class in Listing 10.6 to add a clone method to perform a deep copy on the students field. Listing 10.6-Course.java public class Course private String courselane private Stringt) students- new Stringt11001 private int numberofstudents publie Course (String courselane) this.courseName courseNanez public void addstudent (String student) students [numberofstudents]- student numberofstudents++ publie StringI1 getstudents O return studentS publie at getNunberorstudentso return numberofstudentsi publie String getcourselane O return courselase publie void dropstudent (String student) Left as an exereise in Exereise 99 The implementation listed above will crash i more than 100 students are added. The addStudent method should be rewriten as follows public void addStudent (String student) f (nunStudents100) students [numberotstudentsl-student numberofstudents++ else System.out-printin("Course is full Returning a reference to the students array is a serious security issue since the client class is able to make modifications. The getStadent method should be rewritten as follows publie String getstudents O Stringt1 studentsCopy-new String Inumberofstudents) System.arraycopy (students, studentsCopy, 0, numberofStudents) return studentsCopy
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
