Set of cats

  • 10
  • Locked
You need to create a set of cats. This requires a public static Cat class. Then implement the createCats method, which should create a Set of cats and add 3 cats to it. In the main method, remove one cat from Set cats. Finally, implement the printCats method. It should display all the cats that remain in the set.
You can't complete this task, because you're not signed in.
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Nyerges FerencLevel 18 , Bükkábrány
2 January, 15:48
I also have overridden toString() to make it human readable, which appeared to be mistake. Maybe it worth one note in the requirements as I got used to display only "human readable" things to console.
Miha ČelešnikLevel 9 , Ilirska Bistrica
20 November 2019, 23:12
Same here. Tnx
Kavita RaoLevel 13 , Rockville
4 October 2019, 22:32
Thanks Turner, I too had a name to distinguish the objects and toString method. After removing these, the task passed.
TurnerLevel 11 , Pittsburgh
1 September 2019, 17:31
As mentioned below the hardest part in solving this problem is doing the random access remove using an Iterator. However, the trick into meeting all the other requirements is CODE only what is asked of you. :). I was unable to get the verification to pass until I removed the name and age I had put in my Cat class. I had an overridden toString() and nice formatting of each of my Cat objects printed in my printedCats method, etc. Verification wasn't having none of it. LOL.
JaisinghLevel 13 , Hyderabad
1 October 2018, 14:25
how do i remove an object from the set . i have tried many ways but got nothing. most of the time it says cannot find the symbol not find. "used set.remove method()" but confused with what argument needed to send there so i can remove that element in the set. plz do help me...!!
Ankush RajputLevel 25 , Bhopal
1 October 2018, 14:50
Since set does not guarantee order, you cannot access its elements like an array or arraylist. You'll have to use iterator to access elements of set and remove them. A simple google search will lead you to this -
Kent HerveyLevel 13
4 January, 04:27
I don't have an object variable name, so can't say I don't have any way of saying which cat to remove...