package com.codegym.task.task14.task1414;
import java.util.ArrayList;
import java.io.*;
/*
MovieFactory
*/
public class Solution {
public static void main(String[] args) throws Exception {
ArrayList<Movie> cinema = new ArrayList<Movie>();
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
while (true){
String s = reader.readLine();
if (s.equals("soapOpera")||s.equals("cartoon")||s.equals("thriller")){
cinema.add(MovieFactory.getMovie(s));
} else {
cinema.add(MovieFactory.getMovie(s));
break;
}
}
for(Movie m : cinema){
System.out.println(m.getClass().getSimpleName());
}
}
static class MovieFactory {
static Movie getMovie(String key) {
Movie movie = null;
// Create a SoapOpera object for the key "soapOpera"
if ("soapOpera".equals(key)) {
movie = new SoapOpera();
}
if ("thriller".equals(key)){
movie = new thriller();
}
if ("cartoon".equals(key)){
movie = new cartoon();
}
return movie;
}
}
static abstract class Movie {
}
static class SoapOpera extends Movie {
}
static class cartoon extends Movie{
}
static class thriller extends Movie{
}
}
Compiles even gives the null exeption requested on the requirements, still does not pass the verification, 100 attempst I quit...
Resolved
Comments (5)
- Popular
- New
- Old
You must be signed in to leave a comment
Karas Backend Developer
2 March 2021, 18:02
All in correct Capitalization. Thanks.
0
Guadalupe Gagnon
2 March 2021, 02:02
There is no condition that says null pointer. It says that "For each valid string entered, you need to display the simple name"
0
Guadalupe Gagnon
2 March 2021, 02:03solution
Also, the classes are Cartoon and Thriller, not lowercase
+2
Karas Backend Developer
2 March 2021, 18:08
The getMovie method has to be called anyway on the wrong string also, per the requirements.
Definitelly will not display anything but requires to be called. there it goes attempt number 102.
Thanks.
0
Guadalupe Gagnon
2 March 2021, 18:16
correct, but line 29 should only be reached for each valid entry.
0