Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In this next example, we'll build two classes that implement the Cloneable Interface. The QuizTracker class contains an ArrayList of QuizScore objects, and it's up
In this next example, we'll build two classes that implement the Cloneable Interface. The QuizTracker class contains an ArrayList of QuizScore objects, and it's up to us to build these two classes so that we can make deep copies of QuizTrackers (and share no internal aliases). The key idea here is that to make deep copies of compound objects (or lists of objects), we need to copy (using clone) every object in every list, and even make copies of the list objects (ArrayLists here) themselves. (1) Start by building a small QuizScore Class that contains only one data item: an int that corresponds to the score received on the quiz. (2) Build a second class, QuizTracker, that contains an ArrayList of QuizScore objects (Array List ) as its only data item a. This is just like an IntList covered previously, but instead of ints well be storing QuizScore and instead of arrays we can use an ArrayList here. (3) Add getters and setters to QuizScore for the score, and provide an add(QuizScore) method for class QuizTracker (4)Implement the cloneable interface for the QuizScore class (5) Implement the cloneable interface for the QuizTracker class, as well a. This should not use ArrayList. Clone(), as this is a shallow copy. B. Instead, to create a copy of QuizTracker, you must first build a newly created ArrayList in (b) c. In this way, if we, make a copy of the container (ArrayList), and all the contents in the container (QuizScores), weve succeeded in producing a deep copy for the QuizTracker class
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