Electricity Bill program
Write a program to input the number of units consumed. Calculate the Electricity bill according the given rates.
Write a program to input the number of units consumed. Calculate the Electricity bill according the given rates.
Units consumed Rate
less than 100 80 paisa/unit
For next 200 1 Rs/-
For more than 300 2.50 Rs/-
Print the amount to be paid.
import java.io.*;
class units
{
public static void main()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the units consumed");
double unit=Double.parseDouble(br.readLine());
double amount=0.0;
if(unit<=100)
{
amount=unit*80/100;
}
else if((unit>100)&&(unit<=300))
{
amount=80+(unit-100)*1;
}
else
{
amount=80+(200*1)+(unit-300)*2.50;
}
System.out.println("The amount of money to be paid is "+amount+"Rs");
}
}<tbody>
Enter the units consumed 30
The amount of money to be paid is 24.0 Rs
</tbody>
Related Posts
Continue learning with these related articles
Sum of First n Natural Numbers in Java (Loop and Formula)
Find the sum of the first n natural numbers in Java with a for loop, a while loop and the formula n(n + 1)/2, with a dry run and the sums of even numbers, odd numbers, squares and cubes.
Prime Number Program in Java: Check a Number and Print Primes in a Range
Check whether a number is prime in Java by counting its factors, a faster square-root method with isPrime(), and a program that prints all prime numbers in a range.

Encapsulation, Access Specifiers and Scope of Variables in Java for ICSE Class 10
ICSE Class 10 Computer Applications notes on encapsulation: private, default, protected and public access, data hiding with getter and setter methods, instance vs static (class) variables, local variables and scope, with a solved BankAccount program.