My assignment for class is to create a base class and a subclass, and each one has to have an equals method. Both equals methods are meant to iterate through the indices of an array, but the base class method is for integers and the derived class method is for strings. The equals method in the derived class is supposed to overload the equals method in the base class, but not override it. Right now, the equals method I have in my base class is:
public void equals(int[] equalsList) {
boolean found = false;
for (int i = 0; i < numbers.length; i++) {
equalsList[i] = numbers[i];
}
for (int i = 0; i < equalsList.length; i++) {
for (int j = 1; j > i && j < equalsList.length; j++) {
if(Integer.toString(equalsList[i]).equalsIgnoreCase(Integer.toString(equalsList[j]))) {
found = true;
break;
}
}
if (found) {
System.out.println("You entered a duplicate number. Please restart and only enter each number once.");
System.exit(0);
}
}
}
When I try to pass an array as a parameter in the derived class (ex. super.equals(priorities);, where priorities is an array containing a list of integers), it doesn't work and I still get duplicate numbers. I was able to make it work when I had no parameters at all for the base class equals method, but I need it to have a parameter so it can be overloaded by the equals method of the derived class. Does anyone have any suggestions?
Thanks!!