Advertisement
jaVer404

level07.lesson12.bonus01

Apr 13th, 2015
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.97 KB | None | 0 0
  1. package com.javarush.test.level07.lesson12.bonus01;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.util.ArrayList;
  7.  
  8. /* Нужно исправить программу, чтобы компилировалась и работала
  9. Задача:  Программа вводит с клавиатуры данные про котов и выводит их на экран. Пример:
  10. Cat name is Barsik, age is 6, weight is 5, tail = 22
  11. Cat name is Murka, age is 8, weight is 7, tail = 20
  12. */
  13.  
  14. public class Solution
  15. {
  16.     public final static ArrayList<Cat> CATS = new ArrayList<Cat>();
  17.  
  18.     public static void main(String[] args) throws IOException
  19.     {
  20.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  21.  
  22.         while (true)
  23.         {
  24.             String name = reader.readLine();
  25.             if (name.isEmpty()) break;
  26.             int age = Integer.parseInt(reader.readLine());
  27.             int weight = Integer.parseInt(reader.readLine());
  28.             int tailLength = Integer.parseInt(reader.readLine());
  29.  
  30.  
  31.             Cat cat = new Cat(name, age, weight, tailLength);
  32.  
  33.             CATS.add(cat);
  34.         }
  35.  
  36.         printList();
  37.     }
  38.  
  39.     public static void printList() {
  40.         for (int i = 0; i < CATS.size(); i++)
  41.         {
  42.             System.out.println(CATS.get(i));
  43.         }
  44.     }
  45.  
  46.     public static class Cat
  47.     {
  48.         private String name;
  49.         private int age;
  50.         private int weight;
  51.         private int tailLength;
  52.  
  53.         Cat(String name, int age, int weight, int tailLength)
  54.         {
  55.             this.name = name;
  56.             this.age = age;
  57.             this.weight = weight;
  58.             this.tailLength = tailLength;
  59.         }
  60.  
  61.         @Override
  62.         public String toString()
  63.         {
  64.             return "Cat name is " + name + ", age is " + age + ", weight is " + weight + ", tail = " + tailLength;
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement