Java Program To Calculate Electricity Bill

Java Program to calculate electricity bill. Multiply the wattage of the gadget by the number of hours it is used per day. Multiply by 1000. Subtract your kWh rate from the total. If else is a conditional statement in programming that executes a separate series of statements based on whether an expression is true or false.

class Main
{
public static void main(String args[])
{
int unit=500;
double bill=0;
if(unit<100)
{
bill=unit*1.20;
}
else if(unit<300)
{
bill=100*1.20+(unit-100)*2;
}
else if(unit>300)
{
bill=100*1.20+200*2+(unit-300)*3;
}
System.out.println("Electric bill calculator" + bill);
}
}

 

Output:

Electric bill calculator1120.0

Class in Java

A class is a user-defined blueprint or prototype that is used to build things. It denotes the collection of attributes or methods that are shared by all objects of the same type.

Nested If Statement in Java

A nested if statement is an if statement that is the target of another if or else statement. An if statement nested within another if statement is referred to as a nested if statement. Yes, we may stack if statements within if statements in Java.

Double Keyword in Java

The keyword double denotes the 64-bit float primitive type. The programming language java. lang. When you need to store a double value but also an object reference, the double class is the nominal wrapper class. Using this program we can execute java program to calculate electricity bill.