KnowledgeBoat Logo

Computer Applications

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

Units ConsumedRate Per Unit
First 100 units80 Paisa per unit
Next 200 unitsRs. 1 per unit
Above 300 unitsRs. 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.

Java

Java Conditional Stmts

107 Likes

Answer

import java.util.Scanner;

public class KboatElectricBill
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter Units Consumed: ");
        int units = in.nextInt();
        double amt = 0.0;
        if (units <= 100)
            amt = units * 0.8;
        else if (units <= 300)
            amt = (100 * 0.8) + ((units - 100) * 1);
        else
            amt = (100 * 0.8) + (200 * 1.0) + ((units - 300) * 2.5);
            
        amt += 500;
            
        System.out.println("Units Consumed: " + units);
        System.out.println("Bill Amount: " + amt);
    }
}

Output

BlueJ output of The electricity board charges the bill according to the number of units consumed and the rate as given below: 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.

Answered By

48 Likes


Related Questions