Write a java program for power bill generation with rate per unit is Rs.5/-, passing the arguments through main(). Class 8.
Answers
Answer:
java program power bill generation
Explanation:
import java.util.*;
class ComputeElectricityBill
{
public static int calculateBill(int units)
{
if (units <= 100)
{
return units * 5; // rate per unit given is rs.5
}
else if (units <= 200)
{
return (100 * 5)
+ (units - 100) * 5;
}
else if (units <= 300)
{
return (100 * 5)
+ (100 * 15)
+ (units - 200) * 5;
}
else if (units > 300)
{
return (100 * 5)
+ (100 * 15)
+ (100 * 20)
+ (units - 300) * 5;
}
return 0;
}
public static void main(String args[])
{
int units = 250; // arguments passed in main fun()
System.out.println(calculateBill(units));
}
}
output:
java -cp /tmp/ehcipWZw7w ComputeElectricityBill
2250