java program to input number of unit electricity consumed and calculate electricity bill

Programming Example

An electricity company charges their consumers according to the units consumed per month according to the given traffic:

Units Consumed
Charges
Up to 100 units
₹ 2 per unit
More than 100 units and up to 200 units
₹ 1.80 per unit
More than 200 units
₹ 1.50 per unit

In addition to the above, every consumer has to pay ₹ 200 as Service Charge per month. Write a program to input the amount of units consumed and calculate the total charges payable (Bill) by the consumer.

Solution

import java.util.*;
class Bill
{
    public static void main(String arr[])
    {
        float u,c;
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter the units consumed:");
        u=sc.nextInt();
        if (u<=100)
            c=2*u;
        else if (u<=200)
            c=100*2+(u-100)*1.8f;
        else
            c=100*2+100*1.8f+(u-200)*1.50f;
        c=200+c;
        System.out.println("Amount Payable="+c);
    }
}
Output


CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Website development Company in Allahabad