Advertisement
ya_zay4eg

level07.lesson12.bonus01

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