Advertisement
Alex_Zuev

Untitled

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