import java.util.Arrays;
import java.util.List;
import java.util.Random;
class DynamicArrayOfInts {
private int[] storage;
private int size;
private final int INITIAL_CAPACITY = 8;
private final int GROW_FACTOR = 2;
public DynamicArrayOfInts() {
storage = new int[INITIAL_CAPACITY];
size = 0;
}
private void rangeCheck(int index){
}
private void ensureCapacity(int size_wanted) {
int max_capacity = storage.length;
if (size_wanted > max_capacity) {
max_capacity = max_capacity * GROW_FACTOR +1;
storage = Arrays.copyOf(storage, max_capacity); // increases array size + copy contents
}
}
public int size() {
return -10000; // added so code would compile
}
public boolean equals(Object aThat) { // aThat is a DynamicArrayOfInts object
return false; // added so code would compile
}
public boolean equals(List<Integer> list) { // list is a LinkedList, or ArrayList, etc
return false; // added so code would compile
}
public int get(int position){
return -10000; // added so code would compile
}
public void set(int index, int value){
}
public void insertAt(int index, int value) {
}
public void add(int value) {
}
public void removeAt(int index) {
}
public void printAll() {
}
public static void main(String args[]) {
DynamicArrayOfInts list1 = new DynamicArrayOfInts();
list1.insertAt(0,1);
list1.insertAt(1,2);
list1.add(3);
// list1 is 1, 2, 3
System.out.print("list1: "); list1.printAll();
list1.set(2,100);
// list1 1 is 1, 2, 100
//System.out.print("list1: "); list1.printAll();
System.out.println("list1[2]=" + list1.get(2));
list1.removeAt(2);
// list1 is 1, 2
System.out.print("list1: "); list1.printAll();
DynamicArrayOfInts list2 = new DynamicArrayOfInts();
list2.insertAt(0,2);
list2.insertAt(0,3);
list2.insertAt(0,1);
list2.removeAt(1);
// list2 is 1, 2
System.out.print("list2: ");list2.printAll();
System.out.println("list1.size()=" + list1.size() + ", list2.size()=" + list2.size());
// list1 and list2 are equal
System.out.println("list1 equals list2 is " + list1.equals(list2));
list2.insertAt(2,3);
// list2 is 1, 2, 3
System.out.println("list1.size()=" + list1.size() + ", list2.size()=" + list2.size());
// list1 and list2 are not equal
System.out.println("list1 equals list2 is " + list1.equals(list2));
ArrayList list3 = new ArrayList();
list3.add(1);list3.add(2);list3.add(3);
System.out.println("list2 equals list3 is " + list2.equals(list3));
}
}
so this is the code i am working on for a project. i am supposed to do this for the following method:
method "public boolean equals(Object aThat){": returns true if the int elements in list equal the int elements in the dynamic array. Note that if the size of the list and the size of the dynamic array are not the same, this method can return false without checking the equality of the elements.
the question i have is how to use the Object aThat. what exactly is it, and what am i supposed to do to compare it to an array? if it was an array I assume i could just do array.length and compare the two.