nus-cs2030 / 2223-s1

MIT License
1 stars 0 forks source link

instanceof keyword not allowed in Exercise 4 #75

Open limyeechern opened 2 years ago

limyeechern commented 2 years ago

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.

image
junhuiii commented 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.

limyeechern commented 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.

I used instanceof in the equals method, according to the way equals method is implemented in recitation 2 or 3

junhuiii commented 2 years ago

Why would you need to define an equals method for this exercise?

limyeechern commented 2 years ago

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.

junhuiii commented 2 years ago

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?

bryanongliming commented 2 years ago

You can simply compare the output of toString() to see if the puzzles are the same :)

wilsonwid commented 2 years ago

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 :")

ccheemeng commented 2 years ago

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.