Generating cats

Report a typo

You need to implement the generateNCats method to generate n identical cats. We are not kidding, we need exactly the same cats. You may ask why this might be useful, but this is a quite common situation when writing unit tests when you need objects with any values of their fields. This problem will be especially useful if you apply your knowledge of method / constructor references here.

Write a program in Java 17
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.Stream;

class GenerateCats {

public static List<Cat> generateNCats(int n) {
// write your code here
}

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

List<Cat> cats = generateNCats(scanner.nextInt());

System.out.println(cats.size());
}
}

class Cat {
String name;
int age;
}
___

Create a free account to access the full topic