SHARE
TWEET

Untitled

a guest Jun 12th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.codegym.task.task14.task1411;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.InputStreamReader;
  5.  
  6. /*
  7. User, loser, coder and programmer
  8.  
  9. */
  10.  
  11. public class Solution {
  12.     public static void main(String[] args) throws Exception {
  13.  
  14.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  15.         Person person = null;
  16.         String key = null;
  17.  
  18.         // Here's the loop for reading the keys. Item 1
  19.         while (true)
  20.         {
  21.             // Create an object. Item 2
  22.             key = reader.readLine();
  23.  
  24.             if (key.equals("user")) {
  25.                 person = new Person.User();
  26.             }
  27.             else if (key.equals("loser")) {
  28.                 person = new Person.Loser();
  29.             }
  30.             else if (key.equals("coder")) {
  31.                 person = new Person.Coder();
  32.             }
  33.             else if (key.equals("programmer")) {
  34.                 person = new Person.Programmer();
  35.             }
  36.             else {
  37.                 break;
  38.             }
  39.  
  40.  
  41.             doWork(person); // Call doWork
  42.  
  43.         }
  44.     }
  45.  
  46.     public static void doWork(Person person) {
  47.  
  48.         if (person instanceof Person.User) {
  49.             ((Person.User) person).live();
  50.         }
  51.         else if (person instanceof Person.Loser) {
  52.             ((Person.Loser) person).doNothing();
  53.         }
  54.         else if (person instanceof Person.Coder) {
  55.             ((Person.Coder) person).writeCode();
  56.         }
  57.         else if (person instanceof Person.Programmer) {
  58.             ((Person.Programmer) person).enjoy();
  59.         }
  60.  
  61.     }
  62. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top