I was able to get it to work correctly several ways with the correct output. But the only way that it would Verify was one that gave this output:
"com.codegym.task.task08.task0819.Solution$Cat@28d93b30
com.codegym.task.task08.task0819.Solution$Cat@1b6d3586
Process finished with exit code 0"
So I am happy that I finally got this task done but I am completely confused about how I did it.
Unfortunately Because I did get the answer accepted I am not allowed to post my solution.
I got the task done But I don't understand the output.
Under discussion
Comments (6)
- Popular
- New
- Old
You must be signed in to leave a comment
AlfredW
8 August 2020, 13:04
Thanks for the input.
I will read those outside resources.
0
carolina
7 August 2020, 15:44
This is because you´re trying to print an object, read about the method toString() and how to print an object.
0
carolina
7 August 2020, 15:46
https://www.geeksforgeeks.org/object-tostring-method-in-java/
0
Gellert Varga
12 July 2020, 22:22
Send your code in a personal message, (it is not forbidden), and ask the very concrete question: which part of your code is not clear enough.
But the whole identity code of an object is something like this:
packageName.ClassName@hexadecimalCodeOfObject
(like this: com.codegym.task.task08.task0819.Solution$Cat@28d93b30)
0
AlfredW
12 July 2020, 19:46
I had a hashset of Cat objects
"Set<Cat> cats = new HashSet<Cat>();
Cat Morris = new Cat();
Cat Scratchy = new Cat();
Cat Kitty = new Cat();
cats.add(Morris);
cats.add(Scratchy);
cats.add(Kitty);"
that I removed one from and printed the result:
"
for(Cat cat : cats){
System.out.println(cat);
}"
But my screen output was:
"
"com.codegym.task.task08.task0819.Solution$Cat@28d93b30
com.codegym.task.task08.task0819.Solution$Cat@1b6d3586"
Rather than
"Scratchy
Kitty"
But it was the only way I could get the website to verify my result.
Also I was unable to remove any but the first item in the set:
"for (Cat cat: cats) {
cats.remove( cat );
break;"
All other ways I tried to solve the task would not verify. Even though I was able to get a correct output and have control of which object I removed from the set using other solutions none would verify but ths solution that seems incorrect to me.
0
dnlklnhfr
12 July 2020, 18:05
can you describe a bit more in detail, which part of the task exactly confuses you?
Is it only the way how the console shows he results?
0