ICSE Class 10 Computer Applications
Question 30 of 43
Conditional Constructs in Java — Question 30
Back to all questions 30
Question Question 30
The electricity board charges the bill according to the number of units consumed and the rate as given below:
| Units Consumed | Rate Per Unit |
|---|---|
| First 100 units | 80 Paisa per unit |
| Next 200 units | Rs. 1 per unit |
| Above 300 units | Rs. 2.50 per unit |
Write a program in Java to accept the total units consumed by a customer and calculate the bill. Assume that a meter rent of Rs. 500 is charged from the customer.
import java.util.Scanner;
public class KboatElectricBill
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter Units Consumed: ");
int units = in.nextInt();
double amt = 0.0;
if (units <= 100)
amt = units * 0.8;
else if (units <= 300)
amt = (100 * 0.8) + ((units - 100) * 1);
else
amt = (100 * 0.8) + (200 * 1.0) + ((units - 300) * 2.5);
amt += 500;
System.out.println("Units Consumed: " + units);
System.out.println("Bill Amount: " + amt);
}
}Output
