Lab Exercise #3
for labs meeting Friday, Jan. 31, 2002
Objectives: The purpose of this lab is to implement a small part
of Project 2 and explore shallow and deep copying of array structures.
Part 1:
Implement Part 1 of Project 2: complete and test the methods of the class
ChessPosition,
located in the file programs133/ChessPosition.java.
Part 2:
Now develop a program -- use programs133/Lab3.java as a starting
point -- that will
create a 10-element array A1 of positions.
store position values in the first 5 array locations.
use an ordinary = assignment operator to "copy" A1 to another
array A2. You can just make this method a part of the application
program.
copy A1 to A2 and display the two arrays
modify one of the values in A2 and display again
Now "play with" this program as time allows. Here are some suggestions:
now write a method copy(ChessPosition[]) that implements a deep
copy. That is, A2 = copy(A1) would copy the one array to the other.
copy A1 to A2 and display the two arrays.
use == to see whether A1 and A2 are "equal".
now write a boolean method isEqual(ChessPosition[]) that
implements a "deep" equality test. That is, if B is a boolean
variable, B = A1.isEqual(A2) would do the equality test.