Професионална програма
Loading...
Dimytar1107 avatar Dimytar1107 1 Точки

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. Какъв е проблемът?

Тагове:
0
Java OOP Basics
purshink avatar purshink 5 Точки

Здравейте,

На мен програмата ми работи на конзолата, но като предам в judge ми излиза това съобщение:

The process executing your submission for this test may not have received the output successfully. Please try to submit again the same solution. If the result does not change, then search the error in the submission itself.

 

Може ли помощ ? Това е кодът: 

http://www.filedropper.com/src_3

 

Мерси!

0