C Programs Tutorials | IT Developer
IT Developer

Java Programs



Share with a Friend

Introduction to Java

Java Program: Electricity Bill Calculation Using Slabs

Slab Rates Used in This Example

Units Consumed

Rate per Unit

0–100

₹5

101–200

₹7

201–300

₹10

Above 300

₹15

import java.util.Scanner;

 

public class ElectricityBill {

    public static void main(String[] args) {

 

        Scanner sc = new Scanner(System.in);

 

        System.out.print("Enter total units consumed: ");

        int units = sc.nextInt();

 

        double bill = 0;

 

        if (units <= 100) {

            bill = units * 5;

        }

        else if (units <= 200) {

            bill = (100 * 5) + (units - 100) * 7;

        }

        else if (units <= 300) {

            bill = (100 * 5) + (100 * 7) + (units - 200) * 10;

        }

        else {

            bill = (100 * 5) + (100 * 7) + (100 * 10) + (units - 300) * 15;

        }

 

        System.out.println("Total Electricity Bill: ₹" + bill);

        sc.close();

    }

}

Output

 
OUTPUT 1:
Enter total units consumed: 75
Total Electricity Bill: ₹375.0

Explanation:
75 units → within first slab
Bill = 75 × 5 = ₹375
OUTPUT 2: Enter total units consumed: 150 Total Electricity Bill: ₹850.0

Bill Calculation:

  • 100 × 5 = 500
  • 100 × 7 = 700
  • 100 × 10 = 1000
  • Remaining 25 × 15 = 375

Total = 500 + 700 + 1000 + 375 = ₹2575

(Note: If needed, I can adjust slab calculations based on your electricity board.)

Explanation

1. Input

User enters total electricity units consumed.

2. Slab-wise Calculation

The program applies rates incrementally, not flat-rate.

Ex: If units = 250
→ First 100 at ₹5
→ Next 100 at ₹7
→ Remaining 50 at ₹10

3. Output

Final bill printed in Rupees.