CSC 132 Fall 2000
Lab 2
Due: end of today's lab, 14 September 2000
15 points
"Clone me, Dr. Memory!"
First, grab a copy of IntClonePoly.java and CloneDriver.java from the eccentric download folder for Lab 2. IntClonePoly is just IntArrayPoly with a new name, to avoid confusion with the Lab 1 file. Your assignment will be to add two methods to it: clone() and equals(). These methods should be defined just below the second constructor. The headers for these methods are:
public Object clone()
public boolean equals(Object obj)
See textbook page 127 or IntArrayBag.java (download folder for Chapter 3) for an example of a clone method. Yours will be quite similar. Cloning is discussed on pages 76-80 of your text. See pages 73-76 for a discussion and examples of implementing an equals method. Also refer to your notes from yesterday's class. Two IntClonePoly objects are considered equal if both have the same maxDegree and both have identical coefficient array contents.
Use CloneDriver.java to test your code. Its correct output should be:
p1 is -3+17x+5x^2-1x^5 p2 is -3+17x+5x^2-1x^5 p1 != p2 p1 equals p2 p3 is -3+17x+5x^2-1x^5 p2 == p3 p2 equals p3 p1 != p3 p1 equals p3 p4 is p5 is p4 != p5 p4 does not equal p5 p5 is now p4 != p5 p4 equals p5 p5 is now 1x^10 p4 != p5 p4 does not equal p5
Submit the modified IntClonePoly.java file to your eccentric upload folder. Do NOT submit the driver program.
Javadoc-style comments are NOT required. Bonus points if you can tell me the name of the comedy album from which the name of this assignment was taken. It was recorded in 1971. Good luck.
[ Assignments | CSC 132 | Peter Sanderson | Computer Science | SMSU ]
Last reviewed: 14 September 2000
Peter Sanderson (
PeteSanderson@smsu.edu )