I am currently working on a simple line program in java. There will be no actual GUI, so it is completely text based.
We are required to have a point class and a line class that includes to point objects.
The problem I encountered was involving the equals method for my point class. Considering each point only has two POSITIVE int values, an x and a y, and I'm having issues here, I'm worried I will have problems when I have to compare lines, which will involve comparing the points, the int width and the string color.
This is what the code for my equals method for my point class looks.
@Override
public boolean equals(Point that) {
if(this==that)
return true;
//if
if(this.x==that.getX() && this.y==that.getY())
return true;
return false;
}
Any and all help would be appreciated.
.equals()
takes an Object. You need to make sure the object is not null and the correct type.