Simple Supermarket Billing System Using Java

Simple Supermarket Billing System Using Java​

Abstract:

The java program for a supermarket billing system. The code prompts the user to enter details about each items they are purchasing, such as the item name, quantity, and price. It then stores this information in an ArrayList of Item objects, which is a custom class defined in the code. The program then enters a while loop, which continues to execute until the user enters “exit” as the item name. After the user exits the while loop, the program prompts the user to enter the tax rate and discount amount. It then calculates the total tax, the final total and displays the subtotal, tax, discount and final total. This program uses java’s ArrayList data structure and user defined class Item to keep track of the items purchased and their details. The program can be easily extended and enhanced to include additional features such as bar code scanning, inventory management, and customer database.

Introduction:

Supermarket Billing System is an essential part of any retail store that sells items to customers. It is used to calculate the total cost of the items purchased by a customer, including taxes and discounts. In this article, we will be discussing a Java program that implements a basic Supermarket Billing System.

Explanation:

The program uses a while loop to repeatedly prompt the user to enter details of an item, such as the item name, quantity, and price. It stores this information in an ArrayList of Item objects, which is a custom class defined in the code. The ArrayList of Item objects is useful for creating an inventory system or for printing out a receipt of the items purchased.

The program then prompts the user to enter the tax rate and discount amount. It then calculates the total tax, the final total and displays the subtotal, tax, discount and final total.

The Item class defines a simple object that stores the name, quantity, and price of an item. It has three methods getName(), getQuantity(), getPrice() which are used to retrieve the item’s name, quantity, and price respectively.

The program is relatively simple, but it can be easily extended and enhanced to include additional features such as barcode scanning, inventory management, and customer database.

One of the benefits of using Java for this program is its robustness and scalability. Java is a widely-used, high-level programming language that is suitable for a wide range of applications, including large-scale enterprise systems. It also has a large and active community of developers, making it easy to find solutions to any problems that may arise during the development of the program.

Source Code:

				
					import java.util.ArrayList;
import java.util.Scanner;

public class SupermarketBilling {
    public static void main(String[] args) {
        ArrayList items = new ArrayList();
        Scanner scanner = new Scanner(System.in);
        double total = 0;
        double subTotal = 0;
        double tax = 0;
        double discount = 0;
        double finalTotal = 0;

        System.out.println("Welcome to the Supermarket Billing System");
        System.out.println("Enter the item details:");

        while (true) {
            System.out.print("Enter item name: ");
            String itemName = scanner.next();
            if (itemName.equalsIgnoreCase("exit")) {
                break;
            }
            System.out.print("Enter item quantity: ");
            int itemQuantity = scanner.nextInt();
            System.out.print("Enter item price: ");
            double itemPrice = scanner.nextDouble();
            Item item = new Item(itemName, itemQuantity, itemPrice);
            items.add(item);
            subTotal += itemQuantity * itemPrice;

            System.out.println("Item: " + itemName + ", Quantity: " + itemQuantity + ", Price: $" + itemPrice);
        }

        System.out.print("Enter the tax rate(%): ");
        double taxRate = scanner.nextDouble();
        tax = (taxRate * subTotal) / 100;
        System.out.print("Enter the discount amount($): ");
        discount = scanner.nextDouble();

        finalTotal = subTotal + tax - discount;
        System.out.println("Subtotal: $" + subTotal);
        System.out.println("Tax: $" + tax);
        System.out.println("Discount: $" + discount);
        System.out.println("Total: $" + finalTotal);
    }
}

class Item {
    private String name;
    private int quantity;
    private double price;

    public Item(String name, int quantity, double price) {
        this.name = name;
        this.quantity = quantity;
        this.price = price;
    }

    public String getName() {
        return name;
    }

    public int getQuantity() {
        return quantity;
    }

    public double getPrice() {
        return price;
    }
}
				
			

In conclusion, the Supermarket Billing System is an essential part of any retail store that sells items to customers. The program discussed in this article is a basic implementation of such a system, but can be easily extended and enhanced to meet the specific needs of any retail store. Java is a suitable language for developing such a system due to its robustness, scalability, and the availability of a large and active community of developers.

Output:

Simple Supermarket Billing System using java

Find More Projects

Hostel Management System Using Python With Source Code by using Python Graphical User Interface GUI Introduction: Managing a hostel efficiently can be …

Contra Game Using Python with source code using Pygame Introduction: Remember the super fun Contra game where you fight aliens and jump …

Restaurant Billing Management System Using Python with Tkinter (Graphical User Interface) Introduction: In the bustling world of restaurants, efficiency is paramount, especially …

Jungle Dash Game Using Python with source code with pygame module Introduction: Dive into the excitement of jungle adventures with our new …

Building a Tetris Game with Python with source code Introduction: Welcome to the world of Tetris, where falling blocks meet strategic maneuvers …

Super Mario Game Using Python with source code Introduction: Remember playing Super Mario as a kid? It’s that classic game where you …

All Coding Handwritten Notes

Browse Handwritten Notes