Advertisement
Azazavr

com.javarush.test.level07.lesson12.bonus01

Apr 20th, 2015
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.98 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.  
  25.             String name = reader.readLine();
  26.             if (name.isEmpty()) break;
  27.             int age = Integer.parseInt(reader.readLine());
  28.             int weight = Integer.parseInt(reader.readLine());
  29.             int tail = Integer.parseInt(reader.readLine());
  30.  
  31.  
  32.  
  33.             Cat cat;
  34.             cat = new Cat(name, age, weight, tail);
  35.             CATS.add(cat);
  36.         }
  37.  
  38.         printList();
  39.     }
  40.  
  41.     public static void printList() {
  42.         for (int i = 0; i < CATS.size(); i++)
  43.         {
  44.             System.out.println(CATS.get(i));
  45.         }
  46.     }
  47.  
  48.     public static class Cat
  49.     {
  50.         private String name;
  51.         private int age;
  52.         private int weight;
  53.         private int tailLength;
  54.  
  55.         Cat(String name, int age, int weight, int tailLength)
  56.         {
  57.             this.name = name;
  58.             this.age = age;
  59.             this.weight = weight;
  60.             this.tailLength = tailLength;
  61.         }
  62.  
  63.         @Override
  64.         public String toString()
  65.         {
  66.             return "Cat name is " + name + ", age is " + age + ", weight is " + weight + ", tail = " + tailLength;
  67.         }
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement