Does not want to verify....
"The main method should stop reading strings from the keyboard as soon as the entered string does not match one of the allowed strings ("user", "loser", "coder", "programmer")."
package com.codegym.task.task14.task1411;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/*
1. The main method must read strings from the keyboard.
2. The main method should stop reading strings from the keyboard as soon as the
entered string does not match one of the allowed strings ("user", "loser", "coder", "programmer").
3. For each correctly entered string ("user", "loser", "coder", "programmer"),
call the doWork method with the appropriate Person object as the argument.
4. The Solution class must implement a doWork method with one Person parameter.
5. The doWork method should call the live() method on the passed object if it is a User.
6. The doWork method should call the doNothing() method on the passed object if it is a Loser.
7. The doWork method should call the writeCode() method on the passed object if it is a Coder.
8. The doWork method should call the enjoy() method on the passed object if it is a Programmer.
*/
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
Person person = null;
//String s = null;
// Here's the loop for reading the keys. Item 1 s.equals("user")||s.equals("coder")||s.equals("programmer")||s.equals("loser"
while(true)
{ String s = reader.readLine();
// Create an object. Item 2
if(s.equals("user")){Person user = new Person.User();doWork(user);
}
if(s.equals("loser")){Person loser = new Person.Loser();doWork(loser);
}
if(s.equals("coder")){Person coder = new Person.Coder();doWork(coder);
}
if(s.equals("programmer")){Person programmer = new Person.Programmer();doWork(programmer);
}
else reader.close();
break;
}
}
public static void doWork(Person person) {
if(person instanceof Person.User){((Person.User) person).live();}
else if(person instanceof Person.Loser){((Person.Loser) person).doNothing();}
else if(person instanceof Person.Coder){((Person.Coder) person).writeCode();}
else if(person instanceof Person.Programmer){((Person.Programmer) person).enjoy();}
// Item 3
}
}