In my opinion, the program works well and covers all the requirements, but...take a look at this last requirement from CodeGym.
package pl.codegym.task.task14.task1414;
/*
MovieFactory
*/
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Solution {
public static void main(String[] args) throws Exception {
// Wczytuje parę kluczy (ciągów) z konsoli. Punkt 7
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String key;
Movie movie;
/*
8. Tworzy zmienną movie w klasie Movie i dla każdego wprowadzonego ciągu (klucza):
8.1. Pobiera obiekt za pomocą MovieFactory.getMovie i przypisuje go do zmiennej movie.
8.2. Wyświetla wynik wywoływania metody movie.getClass().getSimpleName().
*/
while (true){
key = br.readLine();
if (key.equals("cartoon") || key.equals("thriller") || key.equals("soapOpera")){
movie = MovieFactory.getMovie(key);
System.out.println(movie.getClass().getSimpleName());
} else {
MovieFactory.getMovie(key);
break;
}
}
}
static class MovieFactory {
static Movie getMovie(String key) {
Movie movie = null;
// Tworzy obiekt SoapOpera dla klucza "soapOpera"
if ("soapOpera".equals(key)) {
movie = new SoapOpera();
//tutaj wpisz swój kod. Punkty 5 i 6
} else if ("cartoon".equals(key)){
movie = new Cartoon();
} else if ("thriller".equals(key)) {
movie = new Thriller();
} else {
System.out.println(key + ": nie ma takiego gatunku filmu");
}
return movie;
}
}
static abstract class Movie {
}
static class SoapOpera extends Movie {
}
// Tutaj napisz swoje klasy Punkt 3
static class Cartoon extends Movie {
}
static class Thriller extends Movie {
}
}