Electricity Bill Program:Write a program in JAVA to enter the unit and calculate the amount to bill paid by user


Calculate the Bill as per the following tariff :


Number of units
Rate per unit
1 - 100 units
Rs.5.00
101-200 units
Rs.7.00

201-300 units

Rs.10.00

Above 300

Rs:15.00


Before we write a program to calculate the electricity bill we must understand electricity charges and rates.



/*1 - 100 unit - 5/= 101-200 unit - 7/=
201-300 unit - 10/= above 300 - 15/=*/ Explanation
if the unit consumed less or equal to 100 units, calculates the total amount of usage =unit*5
if unit consumed between 100 to 200 units, calculates the total amount of usage =(100*5)+(unit-100)*7)
if unit consumed between 200 to 300 units ,calculates total amount of usage
=(100*5)+(100*7)+(unit-200)*10

if unit consumed above 300 units ,calculates total amount of usage
=(100*5)+(100*7)+(100*10)+(unit-300)*15
No additional charge
Source code



import java.util.*;
class Elec
{
    public static void main(String args[])
    {
        int u,amt=0;
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter the units:");
        u=sc.nextInt();
        if(u<=100)
        {
            amt=u*5;
            System.out.println("Bill amount="+amt);
        }
        else if(u>=101 && u<=200)
        {
            amt=100*5+(u-100)*7;
            System.out.println("Bill amount="+amt);
        }
        else if(u>=201 && u<=300)
        {
           amt=100*5+200*7+(u-200)*10;
           System.out.println("Bill amount="+amt);
        }
        else
        {
            amt=100*5+200*7+300*10+(u-300)*15;
           System.out.println("Bill amount="+amt);
        }
       
    }
}
output:
Enter the units:
250
Bill amount=2400

           

Comments

Popular posts from this blog

A school has following rules for grading system: a. Below 25 - F b. 25 to 45 - E c. 45 to 50 - D d. 50 to 60 - C e. 60 to 80 - B f. Above 80 - A Ask user to enter marks and print the corresponding grade.

Write Java program to allow the user to input his/her age. Then the program will show if the person is eligible to vote. A person who is eligible to vote must be older than or equal to 18 years old.

A Computer Salesman gets commission on the following basis using Java