Здравствуйте!
Прошу подсказать, что не так с кодом? Мне кажется, что будто бы должно работать, но не работает.
package com.javarush.task.task14.task1414;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
/*
MovieFactory
*/
public class Solution {
public static void main(String[] args) throws Exception {
ArrayList<String> keyWords = new ArrayList<>();
while (true) {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String key = reader.readLine();
if (!key.equals("soapOpera") && !key.equals("cartoon") && !key.equals("thriller")) {
break;
}
keyWords.add(key);
}
for (String word : keyWords) {
Movie movie = MovieFactory.getMovie(word);
System.out.println(movie.getClass().getSimpleName());
}
}
static class MovieFactory {
static Movie getMovie(String mainKey) throws IOException {
Movie movie = null;
while (true) {
String key = mainKey;
if (!key.equals("soapOpera") && !key.equals("cartoon") && !key.equals("thriller")) {
break;
}
switch (key) {
case "soapOpera":
movie = new SoapOpera();
break;
case "cartoon":
movie = new Cartoon();
break;
case "thriller":
movie = new Thriller();
break;
}
}
return movie;
}
}
static abstract class Movie {
protected Movie() throws IOException {
}
}
static class SoapOpera extends Movie {
protected SoapOpera() throws IOException {
}
}
static class Cartoon extends Movie {
protected Cartoon() throws IOException {
}
}
static class Thriller extends Movie {
protected Thriller() throws IOException {
}
}
}