the requirment number 3 is not met and I don't know why :(
package pl.codegym.task.task14.task1404;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
/*
Koty
*/
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
ArrayList<String> lista = new ArrayList<String>();
String temp = "";
while(true)
{
temp=reader.readLine();
try { if(temp.equals(""))
break;}
catch(NullPointerException e)
{
break;
}
lista.add(temp);
}
for(String a : lista)
{
Cat cat = CatFactory.getCatByKey(a);
System.out.println(cat.toString());
}
}
static class CatFactory {
static Cat getCatByKey(String key) {
Cat cat = null;
if ("dziki".equals(key)) {
cat = new kupCat("Pazur");
} else if ("mańka".equals(key)) {
cat = new FemaleCat("Mania");
} else if ("kafel".equals(key)) {
cat = new NiceCat("Kafelek");
} else {
cat = new Cat(key);
}
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 "Jestem " + getName() + ", podwórkowy kocur";
}
}
public static class kupCat extends Cat{
kupCat(String name){
super(name);}
@Override
public String toString() {
return "Siema jestem " + getName() + ", zaraz zjem ci batona";}
}
public static class MeanCat extends Cat {
MeanCat(String name) {
super(name);
}
public String toString() {
return "Jestem " + getName() + ", zaraz wydrapię Ci oczy";
}
}
public static class NiceCat extends Cat {
NiceCat(String name) {
super(name);
}
public String toString() {
return "Jestem miłą kotką o imieniu " + getName();
}
}
static class FemaleCat extends Cat {
FemaleCat(String name) {
super(name);
}
public String toString() {
return "Jestem słodką kicią i na imię mi " + getName();
}
}
}