So the s.equals never executes, and scanner doesn't read beyond the last line. I think this program works correctly.
package com.codegym.task.task14.task1404;
/*
Cats
*/
import java.util.Scanner;
public class Solution {
public static void main(String[] args) throws Exception {
//write your code here
Scanner scan = new Scanner(System.in);
while (scan.hasNext())
{
String s = scan.nextLine();
if (s.equals("")) System.out.println("BRO");
Cat cat = CatFactory.getCatByKey(s);
System.out.println(cat.toString());
}
scan.close();
}
static class CatFactory {
static Cat getCatByKey(String key) {
Cat cat = null;
if ("boss".equals(key)) {
cat = new MaleCat("Big Boy");
} else if ("miss".equals(key)) {
cat = new FemaleCat("Missy");
} else if ("smudge".equals(key)) {
cat = new FemaleCat("Smudgey");
} else {
cat = new Cat(key);
}
return cat;
}
}
static class Cat {
private String name;
protected Cat(String name) {
this.name = name;
}
public String getName() {
return this.name;
}
public String toString() {
return "I'm " + getName() + ", an alley cat";
}
}
static class MaleCat extends Cat {
MaleCat(String name) {
super(name);
}
public String toString() {
return "I'm a cat powerhouse named " + getName();
}
}
static class FemaleCat extends Cat {
FemaleCat(String name) {
super(name);
}
public String toString() {
return "I'm a cute kitty named " + getName();
}
}
}