Program to calculate the electricity bill


A java class to calculate and print the electricity bill to be paid by a customer. Assume that the customer pays a rent of Rs. 250.00 . Upto 100 units Rs. 1.50. For the next 100 units Rs. 2.00. For next 50 units Rs. 2.50. Beyond 250 units Rs. 4.00.

import java.io.*;
public class ElectricityBill
{
public static void main()throws IOException
{
BufferedReader br=new BufferedReader (new InputStreamReader (System.in));
System.out.print("Enter Your Name : ");
String nm=br.readLine();

System.out.print("Enter the units consumed : ");
int units=Integer.parseInt(br.readLine());

double charges=0,fbill=0;

if(units<=100)
charges=units*1.50;
else if(units<=200)
charges=(100*1.50)+(units-100)*2;
else if(units<=250)
charges=(100*1.50)+(100*2)+(units-200)*2.50;
else
charges=(100*1.50)+(100*2)+(50*2.50)+(units-250)*4;

fbill=charges+250;
System.out.print("\f");
//printing the bill
System.out.println("Your Electricity Bill");
System.out.println("*********************");
System.out.println();
System.out.println("Costumers Name : "+nm);
System.out.println("Units Consumed : "+units);
System.out.println("Charges : "+charges);
System.out.println("Rent Charges : 250 Rs.");
System.out.println("Total Bill : "+fbill);
}
}


Related Articles

Conservation of electricity - the do's and don'ts!

We all use electricity for most of the purposes in our day to day's life. How many of you would think right about the use of electricity? Here in this article, you will find the right ways of using electricity and the ways to conserve electric energy for our future.

Electricity generation from tides

This article describes how electricity generation from tides works. Also some considerations, pros and cons before going in for electricity generation from tides.

More articles: Electricity

Comments



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: