Java
Java
package Java;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.List;
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;
import java.util.HashMap;
import java.util.Map;
producerThread.start();
consumerThread.start();
try {
consumerThread.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
producerThread.interrupt();
}
}
Demonstration:
1. Upon running the program, the "Smart Grocery Manager" interface is displayed in
the terminal.
2. Groceries are continuously produced in the background and shown on the right
side of the terminal.
3. The user is prompted to enter the name of the grocery item they want to purchase
or to enter 'q' to quit.
4. The program checks if the entered item is available in the list of groceries.
5. If the item is available, the program displays its price in rupees and simulates the
purchase process.
6. The purchased item is removed from the list of available groceries.
7. Steps 3-6 are repeated until the user decides to quit by entering 'q'
Out put :