Resources » Articles/Knowledge Sharing » Computer & Technology

Program to calculate the electricity bill


Updated: Category: Computer & Technology
Author: Member Level: SilverPoints: 5


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);
}
}


Did you like this resource? Share it with your friends and show your love!




Responses to "Program to calculate the electricity bill"
Feedbacks      

Post Comment:




  • 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:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Submit Article     Return to Article Index
    Complete the action items below to enter to win an iPad Mini from India Study Channel! in India Study Channel - Locker on LockerDome
    Awards & Gifts
    Active Members
    TodayLast 7 Daysmore...

     
    ISC Technologies, Kochi - India. © All Rights Reserved.