The Coffee class represents a coffee type with its name, price, and recipe (ingredients and their quantities).
The Ingredient class represents an ingredient used in making coffee, with its name and quantity. It provides a synchronized method to update the quantity.
The Payment class represents a payment made by a user, with the amount paid.
The CoffeeMachine class is the main class that manages the coffee vending machine. It follows the Singleton pattern to ensure a single instance of the machine.
The CoffeeMachine class initializes the coffee menu and ingredients in its constructor. It provides methods to display the menu, select a coffee, dispense coffee, and update ingredient quantities.
The hasEnoughIngredients method checks if there are sufficient ingredients to make a selected coffee, while the updateIngredients method updates the ingredient quantities after dispensing a coffee.
The CoffeeVendingMachine class is the entry point of the application and demonstrates the usage of the coffee vending machine. It creates an instance of the machine, displays the menu, and simulates concurrent user requests using an ExecutorService.