Загрузка данных


import java.util.Scanner;

public class Shopping {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        double total = 0;
        int count = 0;
        String list = "";

        System.out.println("Вводи товары. Чтобы закончить, напиши 0");

        while (true) {
            System.out.print("Название: ");
            String name = scanner.nextLine().trim();

            if (name.equals("0") || name.isEmpty()) break;

            System.out.print("Цена: ");
            String priceText = scanner.nextLine().trim();

            double price;
            try {
                price = Double.parseDouble(priceText);
            } catch (Exception e) {
                System.out.println("Цена должна быть числом");
                continue;
            }

            list += name + " — " + price + " руб.\n";
            total += price;
            count++;
        }

        if (count == 0) {
            System.out.println("Ничего не введено");
            return;
        }

        double average = total / count;
        double vat = total * 0.20;
        double withVat = total + vat;

        System.out.println("\n===== СПИСОК ПОКУПОК =====");
        System.out.print(list);
        System.out.println("-------------------------");
        System.out.println("Товаров: " + count);
        System.out.printf("Итого: %.2f руб.%n", total);
        System.out.printf("Средняя цена: %.2f руб.%n", average);
        System.out.printf("НДС 20%%: %.2f руб.%n", vat);
        System.out.printf("К оплате с НДС: %.2f руб.%n", withVat);
    }
}