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


class Product {
    private int id;
    private String name;
    private int priceInCents;
    private int stock;

    Product(int id, String name, int priceInCents, int stock) {
        this.id = id;
        this.name = name;
        this.priceInCents = priceInCents;
        this.stock = stock;
    }

    int getId() { return id; }
    String getName() { return name; }
    int getPriceInCents() { return priceInCents; }
    int getStock() { return stock; }

    void setPriceInCents(int priceInCents) {
        if (priceInCents < 0) {
            System.out.println("Ошибка: цена не может быть отрицательной");
            return;
        }
        this.priceInCents = priceInCents;
    }

    void setStock(int stock) {
        if (stock < 0) {
            System.out.println("Ошибка: остаток товаров не может быть отрицательным");
            return;
        }
        this.stock = stock;
    }

    void setName(String name) {
        if (name == null || name.isEmpty()) {
            System.out.println("Ошибка: название товара не может быть пустым");
            return;
        }
        this.name = name;
    }

    void increaseStock(int quantity) {
        if (quantity <= 0) {
            return;
        }
        stock += quantity;
    }

    void decreaseStock(int quantity) {
        if (quantity <= 0 || quantity > stock) {
            return;
        }
        stock -= quantity;
    }

    boolean isAvailable(int quantity) {
        return quantity > 0 && stock >= quantity;
    }

    String getFormattedPrice() {
        return (priceInCents / 100) + " руб. " + (priceInCents % 100) + " коп.";
    }
}