JAVA Program to calculate Electricity Bill using ‘if’ statement.
How does this program work?
- This code helps to calculate Electricity Bill using ‘if’ statement.
Here is the code
public class bill
{
public static void main(String args[])
{
int m,u,c;
double s,bill;
System.out.println("Enter Curret Meter Number");
Scanner obj=new Scanner(System.in);
m=obj.nextInt();
System.out.println("Enter Number of Units");
u=obj.nextInt();
System.out.println("Choose Category");
System.out.println("1-Agriculture\n2-Residence\n3-Commercial");
c=obj.nextInt();
if(c==1)
{
System.out.println("Agriculture");
s=20;
if(u>0&&u<=50)
{
bill=(u*0.25)+s;
System.out.println("Your bill is="+bill);
}
else
if(u>50&&u<=100)
{
bill=(u*0.50)+s;
System.out.println("Your Bill is="+bill);
}
else
if(u>100&&u<=150)
{
bill=(u*2)+s;
System.out.println("Your Bill is="+bill);
}
else
if(u>150&&u<=200)
{
bill=(u*2.5)+s;
System.out.println("Your Bill is="+bill);
}
else
System.out.println("Invalid units");
}
if(c==2)
{
System.out.println("Residence");
s=30;
if(u>0&&u<=50)
{
bill=(u*2.5)+s;
System.out.println("Your bill is="+bill);
}
else
if(u>50&&u<=100)
{
bill=(u*3)+s;
System.out.println("Your bill is="+bill);
}
else
if(u>100&&u<=150)
{
bill=(u*3.5)+s;
System.out.println("Your bill is="+bill);
}
else
if(u>150&&u<=200)
{
bill=(u*4)+s;
System.out.println("Your bill is="+bill);
}
else
System.out.println("Invalid units");
}
if(c==3)
{
System.out.println("Commercial");
s=50;
if(u>0&&u<=100)
{
bill=(u*3.5)+s;
System.out.println("Your Bill is="+bill);
}
else
if(u>50&&u<=150)
{
bill=(u*4)+s;
System.out.println("Your Bill is="+bill);
}
else
if(u>150&&u<=200)
{
bill=(u*4.5)+s;
System.out.println("Your Bill is="+bill);
}
else
System.out.println("Invalid Units");
}
}
}