Advertisement
Guest User

Cat Lady

a guest
Jun 22nd, 2016
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.65 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.InputStreamReader;
  3. import java.util.HashSet;
  4.  
  5. public class Pr11 {
  6.     public static void main(String[] args) throws Exception {
  7.  
  8.         InputStreamReader isr = new InputStreamReader(System.in);
  9.         BufferedReader reader = new BufferedReader(isr);
  10.  
  11.  
  12.         HashSet<Cat> cats = new HashSet<>();
  13.  
  14.         String line = reader.readLine();
  15.         while (!line.equals("End")) {
  16.             String[] tokens = line.split(" ");
  17.  
  18.             String className = tokens[0];
  19.             String name = tokens[1];
  20.             int property = Integer.parseInt(tokens[2]);
  21.  
  22.             switch (className) {
  23.  
  24.                 case "Siamese":
  25.                     Cat siamese = new Siamese(name, property);
  26.                     cats.add(siamese);
  27.                     break;
  28.                 case "Cymric":
  29.                     Cat cymric = new Cymric(name, property);
  30.                     cats.add(cymric);
  31.                     break;
  32.                 case "StreetExtraordinaire":
  33.                     Cat street = new StreetExtraordinaire(name, property);
  34.                     cats.add(street);
  35.                     break;
  36.                 default:
  37.                     break;
  38.             }
  39.  
  40.             line = reader.readLine();
  41.         }
  42.  
  43.        
  44.         String catToPrint = reader.readLine();
  45.         for (Cat cat: cats) {
  46.             if (cat.name.equals(catToPrint)) {
  47.                 System.out.println(cat.toString());
  48.                 break;
  49.             }
  50.         }
  51.     }
  52.  
  53. }
  54.  
  55. abstract class Cat {
  56.     public String name;
  57.  
  58.     public Cat(String name) {
  59.         this.name = name;
  60.     }
  61.  
  62.     public abstract String toString();
  63. }
  64.  
  65. class Siamese extends Cat {
  66.     public int earSize;
  67.  
  68.     public Siamese(String name, int earSize) {
  69.         super(name);
  70.         this.earSize = earSize;
  71.     }
  72.  
  73.     @Override
  74.     public String toString() {
  75.         return this.getClass().getName() + " " + this.name + " " + this.earSize;
  76.     }
  77. }
  78.  
  79. class Cymric extends Cat {
  80.     public int furLength;
  81.  
  82.     public Cymric(String name,int furLength) {
  83.         super(name);
  84.         this.furLength = furLength;
  85.     }
  86.  
  87.     @Override
  88.     public String toString() {
  89.         return this.getClass().getName() + " " + this.name + " " + this.furLength;
  90.     }
  91. }
  92.  
  93. class StreetExtraordinaire extends Cat {
  94.     public int decibelsOfMeows;
  95.  
  96.     public StreetExtraordinaire(String name, int decibelsOfMeows) {
  97.         super(name);
  98.         this.decibelsOfMeows = decibelsOfMeows;
  99.     }
  100.  
  101.     @Override
  102.     public String toString() {
  103.         return this.getClass().getName() + " " + this.name + " " + this.decibelsOfMeows;
  104.     }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement