Sanjay was shocked after seeing his electricity bill of May month. He approached TNEB
office and asked for more details. TNEB officer explained about the tariff rate and asked to
calculate and check. He was not able to calculate and asked his friend to help. His friend
said it will be calculated based on the Max.Unit. Help Sanjay and his friend to calculate the
amount
N
From Unit
1
To Unit
100
1
101
1.5
1
101
201
1
101
201
501
100
200
100
200
500
100
200
500
Above
Rate (Rs.) Max.Unit
0
100
0
200
200
0
500
2
500
3
500
0 9999999
3.5 9999999
4.6 9999999
6.6 9999999
Input format
Number of units consumed
Output format
Total amount
Answers
Explanation:
// Java implementation to calculate the
// electricity bill
import java.util.*;
class ComputeElectricityBill {
// Function to calculate the
// electricity bill
public static int calculateBill(int units)
{
// Condition to find the charges
// bar in which the units consumed
// is fall
if (units <= 100) {
return units * 10;
}
else if (units <= 200) {
return (100 * 10)
+ (units - 100)
* 15;
}
else if (units <= 300) {
return (100 * 10)
+ (100 * 15)
+ (units - 200)
* 20;
}
else if (units > 300) {
return (100 * 10)
+ (100 * 15)
+ (100 * 20)
+ (units - 300)
* 25;
}
return 0;
}
// Driver Code
public static void main(String args[])
{
int units = 250;
System.out.println(
calculateBill(units));
Answer:
it is correct answer u can try it