Java Program To Calculate Electricity Bill | Example
Beginners Programs :

Java Program To Calculate Electricity Bill | Example

Java program to calculate Electricity bill. If you wondering on how to calculate Electricity bill by writing the Java program there you go. Here we share list of code with sample outputs , in five different ways using static values, using function or method, using command line arguments , do while, for loop, user define method along with sample outputs for each program.

Q.  how to calculate electricity bill ?

Consider the following example:

For example:  a consumer consumes 500 watts per hour daily for one month.  Calculate the total energy bill of that consumer if per unit rate is 7 ? ( In $, £, , INR ,Rs, DHR, Riyal etc) [Take 1 month = 30 Days].

Solution :

electricity bill java code

s we know that 1 Unit = 1kWh

So total kWh = 500 watts x 24 hours x 30 days

= 360000

So, we cant to convert into units:

Where 1 unit = 1kWh

Total consumed units are as: 360000/1000 = 360

And, cost per unit is = 7, the total cost of electricity bill is 360 x 7 = 2520( In $, £, , INR ,Rs, DHR, Riyal etc).

That’s it. Let’s get into programming.

1. Java program to calculate electricity using static method with outputs

There you go by using the standard values along with the sample outputs. If you have any doubts related to the following program do leave a comment here.

output:

2. Taking inputs through scanner class

Java code for obtaining Electricity Bill taking inputs through scanner class, with outputs.

output:

3. Taking Inputs through command line arguments 

Taking inputs through command line arguments with output.

output:

4. Using Inheritance  

output:
 

4. Electricity Bill code by creating a Separate class

Through creating a separate class( ) and taking inputs through scanner class.

output:

 

5. User define method ( Function )

output:
That’s it. Any doubts do let us know.

More programs for you :