Check Electricity Bill Slab

This program calculates electricity bill based on units consumed using if-else ladder.

Problem Statement

Write a Java program that calculates electricity bill based on units consumed.

Source Code

1 public class ElectricityBill {
2 public static void main(String[] args) {
3 int units = 120;
4 if(units <= 50) {
5 System.out.println("Bill: Rs. " + (units * 2) + " - Eduinq");
6 } else if(units <= 100) {
7 System.out.println("Bill: Rs. " + (units * 3) + " - Eduinq");
8 } else {
9 System.out.println("Bill: Rs. " + (units * 5) + " - Eduinq");
10 }
11 }
12 }

Program Output

Bill: Rs. 600 - Eduinq

Explanation

The program uses an if-else ladder to apply different rates based on units consumed. If units are 50 or less, the rate is Rs. 2 per unit. If between 51 and 100, the rate is Rs. 3 per unit. If above 100, the rate is Rs. 5 per unit. This demonstrates how if-else ladders can implement slab-based billing systems, commonly used in utilities. Shows how slab-based billing can be implemented using if-else ladders.

Quick Links to Explore