Output I'm getting:
I'm boss, an alley cat
I'm a nice kitten named Missy
I'm a nice kitten named Smudgey
I'm pirate, an alley cat
My method (I'll post it since it won't pass with this!):
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
String catIn = null;
while ((catIn = r.readLine())!=null){
Cat cat = CatFactory.getCatByKey(catIn.toLowerCase());
System.out.println(cat); }
r.close(); //write your code here
}
It does pass the fourth condition if I leave out the "toLowerCase()" in the method call (then they are all alley cats), but still failing conditions 2 & 3.
It passes when I copied Guadaloupe Gagnon's code from AU Ivan's query, even though it gives exceptions, and only uses Cat class and none of it's child classes (which seems a bit pointless).
I'm very new to this whole coding craic, but I think there's a bit of a glitch here. I'll flag it up anyway. If you read this, thanks for all the help you give everyone GG, mighty man!
Glitch in task i think?
Under discussion
Comments (5)
- Popular
- New
- Old
You must be signed in to leave a comment
Misiu
16 November 2020, 22:54
while ((catIn = r.readLine())!=null)
Empty string is not null.
toLowerCase() - doesn't matter, but may be if we accept strings: Feral, feRAl, ...
0
Dave Shapiro
17 November 2020, 00:38
Didn't realise empty != null, thanks for that!
With the lower case, it's just that when you pass the read strings to the method as is (with caps), none of the other options (child classes of Cat) get used. Actually, having looked at other answers, I think they changed the exercise at some point (from male & female to feral & nice cat) but the input strings are still for the older version.
0
Misiu
17 November 2020, 00:54
I saw three versions of the task in Polish version of the course. There was mismatch with names of cats. But as I remember none of them required lower case.
For me string with upper case character is wrong and should display "alley cat". But I don't know what validator thinks about this.
0
Dave Shapiro
17 November 2020, 11:45
I'd say validator agrees with you :) Thanks again, onwards & upwards, or at least sideways
0
Artem Divertitto Senior Android Developer at United Tech
24 November 2020, 09:24
1. Check smpty string (isEmpty())
2. Delete toLowerCase() method.
0