Solutions for Class 10 ICSE Logix Kips Computer Applications with BlueJ Java | IT Developer <?php echo $page_title; ?>
IT Developer

Conditional Constructs in Java

Chapter 9

Conditional Constructs in Java

Class 9 - Logix Kips ICSE Computer Applications with BlueJ


Share with a Friend

Java Programs - Electricity Bill Calculation Using Slabs


The electricity board charges the bill according to the number of units consumed and the rate as given below:

Units Consumed

Rate Per Unit

First 100 units

80 Paisa per unit

Next 200 units

Rs. 1 per unit

Above 300 units

Rs. 2.50 per unit

Write a program in Java to accept the total units consumed by a customer and calculate the bill. Assume that a meter rent of Rs. 500 is charged from the customer.


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 billAmount = 0;

        double meterRent = 500;

 

        if (units <= 100) {

            billAmount = units * 0.80;

        }

        else if (units <= 300) {

            billAmount = (100 * 0.80) + ((units - 100) * 1.00);

        }

        else {

            billAmount = (100 * 0.80) + (200 * 1.00) + ((units - 300) * 2.50);

        }

 

        double totalBill = billAmount + meterRent;

 

        System.out.println("\n--- Electricity Bill Details ---");

        System.out.println("Units Consumed : " + units);

        System.out.println("Energy Charges : Rs. " + billAmount);

        System.out.println("Meter Rent     : Rs. " + meterRent);

        System.out.println("Total Bill     : Rs. " + totalBill);

 

        sc.close();

    }

}

Output

Output 1 :

SAMPLE INPUT : Enter total units consumed: 80 SAMPLE OUTPUT : --- Electricity Bill Details --- Units Consumed : 80 Energy Charges : Rs. 64.0 Meter Rent : Rs. 500.0 Total Bill : Rs. 564.0

Output 2 :

SAMPLE INPUT : Enter total units consumed: 250 SAMPLE OUTPUT : --- Electricity Bill Details --- Units Consumed : 250 Energy Charges : Rs. 230.0 Meter Rent : Rs. 500.0 Total Bill : Rs. 730.0

Output 3 :

SAMPLE INPUT : Enter total units consumed: 400 SAMPLE OUTPUT : --- Electricity Bill Details --- Units Consumed : 400 Energy Charges : Rs. 530.0 Meter Rent : Rs. 500.0 Total Bill : Rs. 1030.0

Explanation

1. Input

  • Accepts the total units consumed.

2. Slab-wise Calculation

  • First 100 units

               Charge = Units × 0.80

  • Next 200 units

               Charge = (100 × 0.80) + (Remaining Units × 1.00) 

  • Above 300 units

               Charge = (100 × 0.80) + (200 × 1.00) + (Remaining Units × 2.50)

3. Meter Rent

  • A fixed charge of Rs. 500 is added.

4. Final Bill

               Total Bill = Energy Charges + Meter Rent