So supposedly I failed to create a cat for each input entry. however that is false. I made a temp cat for each of those entries utilizing the required class and its method CatFactory. please tell me why this failed.
package com.codegym.task.task14.task1404;
import java.util.ArrayList;
import java.io.*;
/*
Cats
*/
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader kyb = new BufferedReader(new InputStreamReader(System.in));
boolean hasNext = true;
ArrayList<String> cats = new ArrayList<String>();
while (hasNext == true) {
String currentLine = (kyb.readLine()).toLowerCase();
if (currentLine.equals("")) {
hasNext = false;
} else {
cats.add(currentLine);
}
}
for (int i=0; i< cats.size(); i++){
CatFactory factory = new CatFactory();
Cat temp = factory.getCatByKey(cats.get(i));
System.out.println(temp);
}
}
static class CatFactory {
static Cat getCatByKey(String key) {
Cat cat;
switch (key) {
case "feral":
cat = new MeanCat("Claws");
break;
case "miss":
cat = new NiceCat("Missy");
break;
case "smudge":
cat = new NiceCat("Smudgey");
break;
default:
cat = new Cat(key);
break;
}
return cat;
}
}
static class Cat {
private String name;
protected Cat(String name) {
this.name = name;
}
public String getName() {
return this.name;
}
public String toString() {
return "I'm " + getName() + ", an alley cat";
}
}
static class MeanCat extends Cat {
MeanCat(String name) {
super(name);
}
public String toString() {
return "I'm " + getName() + ", and I'm going to claw your eyes out";
}
}
static class NiceCat extends Cat {
NiceCat(String name) {
super(name);
}
public String toString() {
return "I'm a nice kitten named " + getName();
}
}
}