public static class Product implements Comparable<Product> {
    private String productName;
    private double price;

    public Product(String productName, double price){
        this.productName = productName;
        this.price = price;
    }
    public String getProductName() {
        return productName;
    }
    public void setProductName(String productName) {
        this.productName = productName;
    }
    public double getPrice() {
        return price;
    }
    public void setPrice(double price) {
        this.price = price;
    }

    @Override
    public int compareTo(Product product) {
        int result = this.productName.compareTo(product.productName);
        if (result == 0){
            result = this.price.compareTo(product.price);
        }
        return result;
    }

    @Override
    public boolean equals(Product product) {
        if (this == product) return true;
        if (product == null || getClass() != product.getClass()) return false;
        Product product = (Product) product;
        return Double.compare(price, product.price) == 0 && Product.equals(productName, product.productName);
    }

    @Override
    public int hashCode() {
        return Product.hash(productName, price);
    }
}

static public class Human implements Buyer {

    private String firstName;

    private String lastName;
    private double money; // денежный счет человека
    private Set<Product> products; // купленные продукты
    public void buyProduct(Product product, Shop shop) {
        try {
            Shop.sellProduct(this.products);
            products.add(product);
            money = product.getPrice();
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        }


    }


    public Set<Product> getProducts() {
        return products;
    }

    public void setProducts(Set<Product> products) {
        this.products = products;
    }

    public String getFirstName() {
        return firstName;
    }
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }
    public String getLastName() {
        return lastName;
    }
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
    public double getMoney() {
        return money;
    }
    public void setMoney(double money) {
        this.money = money;
    }
    

}


public interface Buyer {
    void buyProduct(Product product, Shop shop);
}


public static class Shop {
    private String name;
    private double money; // денежный счет магазина
    private Map<Product,Integer> products; // продукты и их количество
    //  количество может быть 0 !


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getMoney() {
        return money;
    }

    public void setMoney(double money) {
        this.money = money;
    }

    public Map<Product, Integer> getProducts() {
        return products;
    }

    public void setProducts(Map<Product, Integer> products) {
        this.products = products;
    }

    public static void sellProduct() throws SellProductException {

        Integer value = map.get(product);
       if(value == 0) {
           throw new SellProductException("Продукта с именем " + product.getProductName() + " нет в наличии");
       }
       
        else if(human.getMoney()< product.getPrice){
           throw new SellProductException("Уважаемый " + human.getFirstName() + " " + human.getLastName() + ", для покупки товара недостаточно средств");
       }
        
       else{ double finalMoney = calculateNds(product.getPrice());
        map.put(product, value-1);
        double finalSum = product.getPrice() + finalMoney; 
        human.setMoney(human.getMoney - finalSum); 
         System.out.println(human.getFirstName() + ", вы успешно совершили покупку! C уважением, " + shopName);
         }
    }


    private double calculateNds(double price) {

        double nds = price * 13.0 / 100.0;
        return nds;
    }


    public List<Product> printAndGetAllProductsWithCount() {
        // Должен выводить в консоль все имеющиеся товары и их количество
        // в порядке возрастания по их цене
        // Формат вывода: 1. Пылесос - 2 - 12000.00
        // Должен отдавать список товаров - необходимо для ConsoleService
        

    }

}



public static class SellProductException extends Exception {

    public SellProductException(String message) {
        super(message);
    }
}


public static class ConsoleService {
    private Shop shop;
    private Human human;

    public Human getHuman() {
        return human;
    }

    public void setHuman(Human human) {
        this.human = human;
    }

    public Shop getShop() {
        return shop;
    }

    public void setShop(Shop shop) {
        this.shop = shop;
    }

    public void start() {


        Scanner in = new Scanner(System.in);
        System.out.println("Задайте имя и стартовый капитал магазина: ");
        String vvod = in.nextLine();
        String[] vvod2 = vvod.split(" ");
        String name = vvod2[0];
        String startUpCapital = vvod2[1];
        double money = Double.parseDouble(startUpCapital);
        Shop shop = new Shop(name,money);
        in.close();

        Scanner sc = new Scanner(System.in);
        System.out.println("Укажите количество товаров в формате: название товара, его стоимость и количество в наличии: ");
        String products = sc.nextLine();
        String [] vvod3 = products.split(" ");
        String productName = products[0];
        String price1 = products[1];
        double price = Double.parseDouble(price1);
        String int1 = products[2];
        int productCount = Integer.parseInt(int1);
        Product product = new Product(productName, price);
        Map<String, Integer> products = new HashMap<>();
        products.put(product, productCount);
        sc.close();



        Scanner x = new Scanner(System.in);
        System.out.println("Заполните данные о пользователе (имя, фамилия, количество денежных средств): ");
        String person = x.nextLine();
        String[] person2 = person.split(" ");
        String firstName = person2[0];
        String lastName = person2[1];
        String money2 = person2[2];
        double money = Double.parseDouble(money2);
        Human human = new Human(firstName, lastName, money);
        in.close();

        Scanner y = new Scanner(System.in);
        System.out.println("1. Посмотреть список товаров");
        System.out.println("2. Выход");
        String menu = y.nextLine();
        switch(menu){

            case 1:
                Shop.printAndGetAllProductsWithCount();
                Human.byProduct();
                return;
                break;
            case 2:
                return;
        }



    }
 
} 

Jshell online compiler

Write, Run & Share Jshell code online using OneCompiler's Jshell online compiler for free. It's one of the robust, feature-rich online compilers for Jshell language, running the Jshell version 17. Getting started with the OneCompiler's Jshell editor is easy and fast. The editor shows sample boilerplate code when you choose language as Jshell and start coding.

About Jshell

Jshell is Java’s first official REPL (READ-EVAL-PRINT-LOOP) tool which was introduced in JDK 9 as part of Java Enhancement Proposal. It is suitable to learn the language and also to understand unfamiliar code. With Jshell, you can test the functionality in isolation of a class.

In short, Jshell creates a simple and easy programming environment in the command line which can take input from user, read it and then prints the result.

Syntax help

Variables

When you evaluate any valid java expression, the result will be stored in the system defined variables.
You can also create your own variables

// datatype variable name = value;
int age = 16; // example

Taking inputs (stdin)

By default Jshell creates a new VM to run the code which makes the System.in unavialble to use. OneCompiler has a workaround to this by adding --execution local param. User need to mention this in comments to make use of this option. Following is an example program to demonstrate this

//--execution local
Scanner input = new Scanner(System.in);
System.out.println("Enter your name: ");
String inp = input.next();
System.out.println("Hello, " + inp);

Control statements

1. If-Else:

When ever you want to perform a set of operations based on a condition If-Else is used.

Syntax:

if(condition) {
  // code when condition true
} else {
  // code when condition false
}

Example:

int i = 3
if( i%2 == 0 ) {
   System.out.println("Even number");
} else {
   System.out.println("Odd number");
}

2. For:

For loop is used to iterate a set of statements based on a condition. Usually for loop is preferred when number of iterations is known in advance.

Syntax:

for( Initialization; Condition; Increment/decrement ){  
  //code  
} 

Example:

for(int i = 1; i <= 10; i++ ){
  Systen.out.println(i);
}

3. While:

While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.

while(condition){  
 // code 
}  

4. Do-While:

Do-while is also used to iterate a set of statements based on a condition. It is mostly used when you need to execute the statements atleast once.

do {
  // code 
} while (condition);