I'm simply trying to find the position of an object in a Customer List, although it's constantly returning false when I use the equals()
method.
I now understand that you have to create your own equals
method to override the automatic one, yet I can't understand how to create one when I'm comparing a Customer
inside a Customer
array.
Here are my instance variables:
private Customer[] data;
private int size;
private final static int INITIAL_SIZE = 20;
Here is my method to find the position of the object:
public int findCustomerLocation(String name)
{
int spot = -1;
Customer cus = new Customer(name);
for(int i = 0; i < size ; i++)
{
if((data[i].equals(cus)))
{
spot = i;
System.out.println("spot is:" + spot);
}
else
{
System.out.println("spot not found");
}
}
return spot;
}//findCustomerLocation
(It's returning spot not found)
I'm trying to rewrite the equals
method, but I'm a bit stuck, I'm trying to use if it's an instance of another, but it's still returning false