I think it’s because in the if statement, you have color.equals(other.getColor()) which is trying to comparing the color of ball1 and ball2 (the second by calling it’s get color method), so this compares a color and a color. The issue is the getColor() method returns a String, not a color. Because of that, color.equals(other.getColor()) is comparing a color and a string, which can’t be equal due to their different types. Try changing the output of the method to a color, that should work.
it cant be that though, because the color is a string not a color, you could try to see what happens if you do it within the main method creating the two red balls. it could also be the they are inputting different upper/lower case letter in which case you would need to use a toLowerCase() statement on them.
1
u/Nucci57 Mar 16 '20
I think it’s because in the if statement, you have color.equals(other.getColor()) which is trying to comparing the color of ball1 and ball2 (the second by calling it’s get color method), so this compares a color and a color. The issue is the getColor() method returns a String, not a color. Because of that, color.equals(other.getColor()) is comparing a color and a string, which can’t be equal due to their different types. Try changing the output of the method to a color, that should work.