To me everything asked is done but can't pass steps 2 and 3
package fr.codegym.task.task14.task1404;
import java.io.*;
import java.util.ArrayList;
/*
Chats
*/
public class Solution {
public static void main(String[] args) throws Exception {
//écris ton code ici
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
ArrayList<String> liste = new ArrayList<String>();
while (true) {
String parametre = reader.readLine();
if (parametre == null) {
reader.close();
break;
}
else
liste.add(parametre);
}
ArrayList<Cat> catList = new ArrayList<Cat>();
for (String element : liste) {
catList.add(CatFactory.getCatByKey(element));
}
for (Cat cat : catList){
System.out.println(cat.toString());
}
}
static class CatFactory {
static Cat getCatByKey(String key) {
Cat cat = null;
if ("sauvage".equals(key)) {
cat = new MeanCat("Griffeur");
} else if ("miss".equals(key)) {
cat = new NiceCat("Missy");
} else if ("fil".equals(key)) {
cat = new NiceCat("Filoute");
} 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 "Je m'appelle " + getName() + ", et je suis un chat de gouttière";
}
}
static class MeanCat extends Cat {
MeanCat(String name) {
super(name);
}
public String toString() {
return "Je m'appelle " + getName() + ", et je vais t'arracher les yeux";
}
}
static class NiceCat extends Cat {
NiceCat(String name) {
super(name);
}
public String toString() {
return "Je suis un gentil chaton et je m'appelle " + getName();
}
}
}