Facebook
From Bulky Pintail, 4 Years ago, written in Plain Text.
This paste is a reply to Untitled from Wet Frog - view diff
Embed
Download Paste or View Raw
Hits: 366
  1. import java.util.ArrayList;
  2. import java.util.Scanner;
  3.  
  4. public class Main
  5. {
  6.     public static void main(String[] args)
  7.     {
  8.         ArrayList<Animal> animals=new ArrayList<>();
  9.         animals.ensureCapacity(10);
  10.         Scanner scanner=new Scanner(System.in);
  11.         System.out.println("age:   weight:   name:   breed:");
  12.         for(int i=0;i<5;i++)
  13.         {
  14.             Animal animal=new Animal(scanner.nextInt(),scanner.nextDouble(),scanner.nextLine(),scanner.nextLine());
  15.             animals.add(animal);
  16.            // animals.add(new Animal(scanner.nextInt(),scanner.nextDouble(),scanner.nextLine(),scanner.nextLine()));
  17.         }
  18.        /* animals.add(new Animal(12,22,"Hound","Rufus"));
  19.         animals.add(new Animal(11,56,"Andrew","Carrot"));
  20.         animals.add(new Animal(43,44,"Antonio","Banderas"));
  21.  
  22.         */
  23.  
  24.         for(Animal e:animals)
  25.         {
  26.  
  27.             System.out.println(e.toString());
  28.         }
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.     }
  36.  
  37.  
  38. }
  39.  
  40.  
  41. package codeWars;
  42.  
  43. public class Animal
  44. {
  45.     private int age;
  46.     private double weight;
  47.     private String name;
  48.     private String breed;
  49.  
  50.     public Animal(int age,double weight,String name,String  breed)
  51.     {
  52.         this.age=age;
  53.         this.weight=weight;
  54.         this.name=name;
  55.         this.breed=breed;
  56.     }
  57.  
  58.     public  String getBreed()
  59.     {
  60.         return breed;
  61.     }
  62.  
  63.     public Animal()
  64.     {
  65.  
  66.     }
  67.     public int getAge() {
  68.         return age;
  69.     }
  70.  
  71.     public double getWeight() {
  72.         return weight;
  73.     }
  74.  
  75.     public String getName() {
  76.         return name;
  77.     }
  78.  
  79.     public void setName(String name) {
  80.         this.name = name;
  81.     }
  82.  
  83.     public String toString()
  84.     {
  85.         return getClass().getName()+" age: "+age+" weight: "+weight+" name "+ name+ " breed "+breed;
  86.     }
  87. }
  88.