For each string entered (including the invalid string), you must call the MovieFactory.getMovie method.
recomendations from your mentor ; Be sure that the getMovie method is not called more than necessary.
package com.codegym.task.task14.task1414;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/*
MovieFactory
*/
public class Solution {
public static void main(String[] args) throws Exception {
// Read several keys (strings) from the console. Item 7
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String s = null;
Movie movie = null;
/*
8. Create a variable movie in the Movie class, and for each entered string (key):
8.1. Get an object using MovieFactory.getMovie and assign it to the variable movie.
8.2. Display the result of calling movie.getClass().getSimpleName().
*/
while(true){
s = reader.readLine();
MovieFactory.getMovie(s);
if(s.equalsIgnoreCase("soapOpera")){
System.out.println( MovieFactory.getMovie(s).getClass().getSimpleName());}
else if(s.equalsIgnoreCase("cartoon")){
System.out.println( MovieFactory.getMovie(s).getClass().getSimpleName());}
else if(s.equalsIgnoreCase("thriller")){
System.out.println( MovieFactory.getMovie(s).getClass().getSimpleName());}
else {break;}
}
}
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("cartoon".equals(key)){
movie = new Cartoon();
}
if("thriller".equals(key)){
movie = new Thriller();
}
//write your code here. Items 5, 6
return movie;
}
}
static abstract class Movie {
public Movie movie;
}
static class SoapOpera extends Movie {
}
static class Cartoon extends Movie {}
static class Thriller extends Movie{}
// Write your classes here. Item 3
}