import [Link].
*;
import [Link].*;
import [Link];
public class GroceryStoreBilling {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
// Products in store (NO DATABASE)
List<Item> products = new ArrayList<>();
[Link](new Item(1, "Rice 5kg", 250));
[Link](new Item(2, "Wheat Flour 5kg", 200));
[Link](new Item(3, "Sugar 1kg", 40));
[Link](new Item(4, "Milk 1L", 30));
[Link](new Item(5, "Oil 1L", 120));
// cart using HashMap → merges quantity if repeated
Map<Integer, CartEntry> cart = new HashMap<>();
String storeName = "SUPER MART GROCERY STORE";
[Link]("\
n============================================
===");
[Link](" " + storeName);
[Link](" GROCERY STORE BILLING SYSTEM");
[Link]("================================
===============");
boolean continueShopping = true;
while (continueShopping) {
[Link]("\n------------- PRODUCT MENU -------------");
for (Item i : products) {
[Link]([Link] + ". " + [Link] + " - Rs. " + [Link]);
[Link]("0. Finish & Generate Bill");
[Link]("----------------------------------------");
[Link]("Enter Product Number: ");
int choice = [Link]();
if (choice == 0) break;
Item selected = null;
for (Item i : products) {
if ([Link] == choice) {
selected = i;
break;
if (selected == null) {
[Link]("❌ Invalid product number. Try again.");
continue;
[Link]("Enter Quantity: ");
int qty = [Link]();
if (qty <= 0) {
[Link]("❌ Quantity must be greater than 0!");
continue;
// Add to cart → combine quantity if product already exists
if ([Link]([Link])) {
[Link]([Link]).quantity += qty;
} else {
[Link]([Link], new CartEntry(selected, qty));
[Link]("✔ Added: " + [Link] + " x " + qty);
// SPECIAL CONDITION:
// If customer bought 2 or more products, give option to add more
if ([Link]() >= 2) {
[Link]("Do you want to add more products? (yes/no):
");
String ans = [Link]().toLowerCase();
if () {
continueShopping = false;
}
generateBill(cart, storeName);
[Link]();
// BILL PRINTING METHOD
public static void generateBill(Map<Integer, CartEntry> cart, String
storeName) {
// Get current date & time
LocalDateTime now = [Link]();
DateTimeFormatter dateFormatter =
[Link]("dd-MM-yyyy");
DateTimeFormatter timeFormatter =
[Link]("HH:mm:ss");
[Link]("\n==================== FINAL BILL
====================");
[Link]("Store: " + storeName);
[Link]("Date: " + [Link](dateFormatter));
[Link]("Time: " + [Link](timeFormatter));
[Link]("----------------------------------------------------");
[Link]("%-20s %-10s %-10s %-10s\n",
"Product", "Price", "Qty", "Total");
[Link]("----------------------------------------------------");
double grandTotal = 0;
for (CartEntry entry : [Link]()) {
double lineTotal = [Link] * [Link];
grandTotal += lineTotal;
[Link]("%-20s %-10.2f %-10d %-10.2f\n",
[Link], [Link],
[Link], lineTotal);
[Link]("----------------------------------------------------");
[Link]("GRAND TOTAL: Rs. %.2f\n", grandTotal);
[Link]("================================
====================");
[Link](" THANK YOU! VISIT AGAIN");
[Link]("================================
====================\n");
// ITEM CLASS
class Item {
int id;
String name;
double price;
Item(int id, String name, double price) {
[Link] = id;
[Link] = name;
[Link] = price;
// CART ENTRY CLASS
class CartEntry {
Item item;
int quantity;
CartEntry(Item item, int quantity) {
[Link] = item;
[Link] = quantity;