Electric Bill

Given the number of electrical units consumed the task is to calculate and display the total amount payable. Follow the below given cost chart.

  • Upto 50 units 2 ₹/unit
  • From 51 to 150 units 4 ₹/unit
  • From 151 to 300 units 6 ₹/unit
  • More than 300 units 8 ₹/unit
Java
import java.util.*;
public class ElectricBill
{
    public static void main(String args[])
    {
        int u=0;
        double charge=0;
        Scanner sc=new Scanner(System.in);
        System.out.print("Consumed Units: ");
        u=sc.nextInt();
        if(u>0&&u<=50)
        {
            charge=u*2;
        }
        else if(u>50&&u<=150)
        {
            charge=u*4;
        }
        else if(u>150&&u<=300)
        {
            charge=u*6;
        }
        else if(u>300)
        {
            charge=u*8;
        }
        else
        {
            System.out.println("Number of units can not be zero or negative");
        }
        System.out.println("Payable Amount: Rs "+charge);
    }
}
Java