Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- import java.util.HashSet;
- public class Pr11 {
- public static void main(String[] args) throws Exception {
- InputStreamReader isr = new InputStreamReader(System.in);
- BufferedReader reader = new BufferedReader(isr);
- HashSet<Cat> cats = new HashSet<>();
- String line = reader.readLine();
- while (!line.equals("End")) {
- String[] tokens = line.split(" ");
- String className = tokens[0];
- String name = tokens[1];
- int property = Integer.parseInt(tokens[2]);
- switch (className) {
- case "Siamese":
- Cat siamese = new Siamese(name, property);
- cats.add(siamese);
- break;
- case "Cymric":
- Cat cymric = new Cymric(name, property);
- cats.add(cymric);
- break;
- case "StreetExtraordinaire":
- Cat street = new StreetExtraordinaire(name, property);
- cats.add(street);
- break;
- default:
- break;
- }
- line = reader.readLine();
- }
- String catToPrint = reader.readLine();
- for (Cat cat: cats) {
- if (cat.name.equals(catToPrint)) {
- System.out.println(cat.toString());
- break;
- }
- }
- }
- }
- abstract class Cat {
- public String name;
- public Cat(String name) {
- this.name = name;
- }
- public abstract String toString();
- }
- class Siamese extends Cat {
- public int earSize;
- public Siamese(String name, int earSize) {
- super(name);
- this.earSize = earSize;
- }
- @Override
- public String toString() {
- return this.getClass().getName() + " " + this.name + " " + this.earSize;
- }
- }
- class Cymric extends Cat {
- public int furLength;
- public Cymric(String name,int furLength) {
- super(name);
- this.furLength = furLength;
- }
- @Override
- public String toString() {
- return this.getClass().getName() + " " + this.name + " " + this.furLength;
- }
- }
- class StreetExtraordinaire extends Cat {
- public int decibelsOfMeows;
- public StreetExtraordinaire(String name, int decibelsOfMeows) {
- super(name);
- this.decibelsOfMeows = decibelsOfMeows;
- }
- @Override
- public String toString() {
- return this.getClass().getName() + " " + this.name + " " + this.decibelsOfMeows;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement