Facebook
From Bulky Pintail, 4 Years ago, written in Plain Text.
This paste is a reply to Untitled from Wet Frog - go back
Embed
Viewing differences between Untitled and Re: Untitled
import java.util.ArrayList;
import java.util.Scanner;

public class Main
{
    public static void main(String[] args)
    {
        ArrayList animals=new ArrayList<>();
        animals.ensureCapacity(10);
        Scanner scanner=new Scanner(System.in);
        System.out.println("age:   weight:   name:   breed:");
        for(int i=0;i<5;i++)
        {
            Animal animal=new Animal(scanner.nextInt(),scanner.nextDouble(),scanner.nextLine(),scanner.nextLine());
            animals.add(animal);
           // animals.add(new Animal(scanner.nextInt(),scanner.nextDouble(),scanner.nextLine(),scanner.nextLine()));
        }
       /* animals.add(new Animal(12,22,"Hound","Rufus"));
        animals.add(new Animal(11,56,"Andrew","Carrot"));
        animals.add(new Animal(43,44,"Antonio","Banderas"));

        */

        for(Animal e:animals)
        {

            System.out.println(e.toString());
        }






    }


}


package codeWars;

public class Animal
{
    private int age;
    private double weight;
    private String name;
    private String breed;

    public Animal(int age,double weight,String name,String  breed)
    {
        this.age=age;
        this.weight=weight;
        this.name=name;
        this.breed=breed;
    }

    public  String getBreed()
    {
        return breed;
    }

    public Animal()
    {

    }
    public int getAge() {
        return age;
    }

    public double getWeight() {
        return weight;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String toString()
    {
        return getClass().getName()+" age: "+age+" weight: "+weight+" name "+ name+ " breed "+breed;
    }
}