wildFarm
public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); Map<String, Animal> animals = new LinkedHashMap<>(); String type; String input; while (!"End".equals(input = scanner.nextLine())) { String[] animalInfo = input.split("\\s+"); type = animalInfo[0]; String name = animalInfo[1]; double weight = Double.parseDouble(animalInfo[2]); String region = animalInfo[3]; switch (type) { case "Tiger" -> { Animal tiger = new Tiger(type, name, weight, region); animals.put("Tiger", tiger); } case "Zebra" -> { Animal zebra = new Zebra(type, name, weight, region); animals.put("Zebra", zebra); } case "Mouse" -> { Animal mouse = new Mouse(type, name, weight, region); animals.put("Mouse", mouse); } } if (type.equals("Cat")) { String breed = animalInfo[4]; Animal cat = new Cat(type, name, weight, region, breed); animals.put("Cat", cat); } animals.get(type).makeSound(); String foodLine = scanner.nextLine(); String[] foodInfo = foodLine.split("\\s+"); String foodName = foodInfo[0]; int foodWeight = Integer.parseInt(foodInfo[1]); Food food; if (foodName.equals("Vegetable")) { food = new Vegetable(foodWeight); } else { food = new Meat(foodWeight); } try { animals.get(type).eat(food); } catch (IllegalArgumentException ex) { System.out.println(ex.getMessage()); } } animals .forEach((key, value) -> System.out.println(value.toString())); } }
Здравейте, имам следния проблем. Програмата свършва с изчерпването на while цикъла и не отпечатва последната команда за animals. Какъв е проблемът?