Witam,
czy ktoś mógłby podpowiedzieć jak sprawić żeby ten kod zadziałał (tzn powinna się wydrukować zawartość listy)
public class Solution
{
public final static ArrayList<Cat> CATS = new ArrayList<Cat>();
public static void main(String[] args) throws IOException
{
Scanner sc = new Scanner(System.in);
while (true)
{
String name = sc.nextLine();
int age = sc.nexInt();
int weight = sc.nextInt();
int tailLength = sc.nextInt();
if (!name.isEmpty()) {
break;
} else {
Cat cat = new Cat(name, age, weight, tailLength);
CATS.add(cat);
}
}
printList();
}
public static void printList() {
for (int i = 0; i < CATS.size(); i++)
System.out.println(CATS.get(i));
}
public static class Cat
{
private String name;
private int age;
private int weight;
private int tailLength;
Cat(String name, int age, int weight, int tailLength)
{
this.name = name;
this.age = age;
this.weight = weight;
this.tailLength = tailLength;
}
@Override
public String toString()
{
return "Cat name is " + name + ", age is " + age + ", weight is " + weight + ", tail = " + tailLength;
}
}
}
Z góry dziękuje!