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

Information about Electricity

Present day man cannot imagine his life without Electricity. It has become a basic need right from the moment he wakes up in the morning. It can be called as a great gift of nature. In this article I am giving you little information about electricity. I mean how it was discovered and by whom.

Hydro power generation

In this article, I will explain the use of turbine and its necessity according to the site, environment, flow and height. The basic fundamentals of hydro power generation on hilly region will also be explained. Before starting the project some clearances needed by the particular company from different resources. Many of those related with the political issues, affect on living beings and environment.

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.

Tips for purchasing best Air Conditioner for self- buying guide

Today AC is not a luxury but has become a necessity. The increase in market competition is proving beneficial to the general consumers. Companies are now compelled to sell better products on a cheaper price. Today everybody wishes to make his life style comfortable. The expenditure on AC is no more taken as a token of affluence but a necessity. If you are going to install AC, the factors to be remembered are detailed in this piece.

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: