C Programs Tutorials | IT Developer
IT Developer

Java Programs



Share with a Friend

Operators & Expressions

Java Program: Discount Calculation with Multiple Slabs

Discount Slabs (Example)

Purchase Amount

Discount

Below ₹1,000

No Discount

₹1,000 – ₹4,999

5%

₹5,000 – ₹9,999

10%

₹10,000 and above

15%

import java.util.Scanner;

 

public class DiscountCalculator {

    public static void main(String[] args) {

 

        Scanner sc = new Scanner(System.in);

 

        System.out.print("Enter purchase amount: ");

        double amount = sc.nextDouble();

 

        double discountRate;

 

        // Determine discount using slabs

        if (amount < 1000) {

            discountRate = 0;

        }

        else if (amount < 5000) {

            discountRate = 0.05;

        }

        else if (amount < 10000) {

            discountRate = 0.10;

        }

        else {

            discountRate = 0.15;

        }

 

        double discount = amount * discountRate;

        double finalAmount = amount - discount;

 

        System.out.println("\n------ Discount Calculation ------");

        System.out.printf("Original Amount : ₹%.2f%n", amount);

        System.out.printf("Discount Rate   : %.0f%%%n", discountRate * 100);

        System.out.printf("Discount Amount : ₹%.2f%n", discount);

        System.out.printf("Final Amount    : ₹%.2f%n", finalAmount);

 

        sc.close();

    }

}

Output

 
OUTPUT 1:

INPUT : 
Enter purchase amount: 3200

OUTPUT : 
------ Discount Calculation ------
Original Amount : ₹3200.00
Discount Rate   : 5%
Discount Amount : ₹160.00
Final Amount    : ₹3040.00

OUTPUT 2:

INPUT : 
Enter purchase amount: 8500

OUTPUT : 
------ Discount Calculation ------
Original Amount : ₹8500.00
Discount Rate   : 10%
Discount Amount : ₹850.00
Final Amount    : ₹7650.00


OUTPUT 3:

INPUT : 
Enter purchase amount: 12000

OUTPUT : 
------ Discount Calculation ------
Original Amount : ₹12000.00
Discount Rate   : 15%
Discount Amount : ₹1800.00
Final Amount    : ₹10200.00

Explanation

  1. Input Purchase Amount

double amount = sc.nextDouble();

  • Reads the total purchase value.
  1. Determine Discount Slab

if (amount < 1000)

...

else if (amount < 5000)

...

  • Uses if–else if ladder to select correct discount slab.
  1. Discount Calculation

Discount = Amount × Discountnbsp;Rate
Final Amount = Amount − Discount

  1. Formatted Output

System.out.printf("%.2f", value);

  • Displays monetary values with 2 decimal places.
  • %% prints % symbol.

Key Concepts Used

Conditional statements (if–else)
Percentage calculations
Arithmetic expressions
User input using Scanner
Formatted output

📌 Short Exam Answer

This program calculates discount based on multiple slabs using conditional statements. It computes the discount amount and final payable amount according to the purchase value.