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.
- First 1 to 200 units 5 ₹/unit.
- Next 201 to 400 units 7 ₹/unit.
- More than 400 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.print("Customer name: ");
name=sc.nextLine();
System.out.print("Units consumed: ");
units=sc.nextInt();
System.out.println();
if(units>=0&&units<=200)
{
bill=(units*5)+50;
}
else if(units>200&&units<=400)
{
bill=((200-0)*5)+((units-200)*7)+50;
}
else if(units>400)
{
bill=((200-0)*5)+((400-200)*7)+((units-400)*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