Electricity Bill

Write a program to accept customer name and number of electrical units consumed from the user and calculate the payable amount after based on the given tariff.

  • Upto 200 units 5 ₹/unit.
  • From 201 to 500 units 7 ₹/unit.
  • More than 500 units 10 ₹/unit.
Java
import java.util.*;
public class EBill
{
    public static void main(String args[])
    {
        String name="";
        int units=0;
        double bill=0.0;
        Scanner sc=new Scanner(System.in);
        System.out.println("Customer name: ");
        name=sc.nextLine();
        System.out.println("Units consumed: ");
        units=sc.nextInt();
        System.out.println();
       if(units>0&&units<=200)
        {
            bill=(units*5)+50;
        }
        else if(units>200&&units<=500)
        {
            bill=(units*7)+50;
        }
        else if(units>500)
        {
            bill=(units*10)+50;
        }
        else
        {
            System.out.println("Number of units can not be zero or negative");
        }
        System.out.println("Customer Name: "+name);
        System.out.println("Number of units consumed: "+units);
        System.out.println("Amount to be paid: "+bill);
    }
}
Java