Why the last condition not matching......
package com.codegym.task.task14.task1414;
/*
MovieFactory
*/
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
Movie movie = null;
while (true) {
System.out.print("Enter key : ");
String key = reader.readLine();
movie = MovieFactory.getMovie(key);
if (!(key.equals("cartoon") || key.equals("thriller") || key.equals("soapOpera")))
{
// movie = MovieFactory.getMovie(key);
// System.out.println(movie.getClass().getSimpleName());
break;
}
System.out.println(movie.getClass().getSimpleName());
}
/*
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().
*/
}
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();
}
else if ("thriller".equals(key))
{
movie = new Thriller();
}
else if ("cartoon".equals(key))
{
movie = new Cartoon();
}
return movie;
}
}
static abstract class Movie {
// Movie movie = null;
}
static class SoapOpera extends Movie {
}
static class Thriller extends Movie {
}
static class Cartoon extends Movie {
}
}