Open limyeechern opened 2 years ago
Can I ask what are you using the instanceof keyword for in Exercise 4? I didn't use it and still managed to get the answer, so you may want to consider changing your implementation.
Can I ask what are you using the instanceof keyword for in Exercise 4? I didn't use it and still managed to get the answer, so you may want to consider changing your implementation.
I used instanceof in the equals method, according to the way equals method is implemented in recitation 2 or 3
Why would you need to define an equals method for this exercise?
Why would you need to define an equals method for this exercise?
The solution I thought of to check if the puzzle is solved is it check if the puzzle is equals to a new puzzle of same dimensions, which will be in the correct/solved order.
Ahh ok understood, I manually went to check if the positions are the same, hence I didn't write a .equals() method.
Don't think there's anything wrong your implementation honestly, just that CodeCrunch doesn't want you to use instanceof....maybe try removing it for this exercise, since there is isn't any inheritance at play so to speak?
You can simply compare the output of toString() to see if the puzzles are the same :)
I don't think you need to define an equals()
method as you can manually compare elements manually. Likewise, comparing the output of the toString()
works too :")
To add on to Bryan's suggestion, if you wish to use the equals method you can use the String.equals() method to compare the .toString() outputs of the puzzle and the solution.
Hi, the keyword instanceof is disallowed in Exercise 4 although the equals method that we are taught in recitation involved the use of instanceof. Is there a way to allow instanceof keyword only in this equals method for this exercise? Otherwise we might need to typecast to implement the equals method, which Prof does not like.