package pl.codegym.task.task14.task1404; /* Koty */ import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; public class Solution { public static void main(String[] args) throws Exception { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); ArrayList<String> kotki = new ArrayList<>(); String napis = null; while (true){ try { napis = reader.readLine(); }catch (Exception e){ System.out.println("mam jakis blad powtorz wpisanie imienia"); napis = reader.readLine(); }finally { if(napis.equals("") ){ break; } /*or Cat cat = CatFactory.getCatByKey(text); System.out.println(cat); this solution without the ArrayList (1) */ kotki.add(napis); } } for(String text : kotki) { //(2) Cat cat = CatFactory.getCatByKey(text); System.out.println(cat.toString()); } } static class CatFactory { static Cat getCatByKey(String key) { Cat cat = null; if ("dziki".equals(key)) { cat = new FemaleCat("Pazur"); } else if ("mańka".equals(key)) { cat = new FemaleCat("Mania"); } else if ("kafel".equals(key)) { cat = new MaleCat("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"; } } static class MaleCat extends Cat { MaleCat(String name) { super(name); } public String toString() { return "Jestem " + getName() + ", zaraz wydrapię Ci oczy"; } } static class FemaleCat extends Cat { FemaleCat(String name) { super(name); } public String toString() { return "Jestem miłą kotką o imieniu " + getName(); } } }