- Home
- Chapter 1 - Object Oriented Programming Concepts
- Object Oriented Programming Concepts
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 2 - Introduction to Java
- Introduction to Java
- Multiple Choice Questions
- Assignment Questions
- Chapter 3 - Values and Data Types
- Values and Data Types
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 4 - Operators in Java
- Operators in Java
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 5 - User-Defined Methods
- User-Defined Methods
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 6 - Input in Java
- Input in Java
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 7 - Mathematical Library Methods
- Mathematical Library Methods
- Multiple Choice Questions
- Assignment Questions
- Chapter 8 - Conditional Constructs in Java
- Conditional Constructs in Java
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 9 - Iterative Constructs in Java
- Iterative Constructs in Java
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions and Programs
- Chapter 10 - Nested for loops
- Nested for loops
- Assignment Questions and Programs
- Chapter 11 - Constructors
- Constructors
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 12 - Library Classes
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 13 - Encapsulation and Inheritance
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 14 - Arrays
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 15 - String Handling
- Library Classes
- Multiple Choice Questions
- Assignment Questions
Conditional Constructs in Java
Chapter 9
Conditional Constructs in Java
Class 9 - Logix Kips ICSE Computer Applications with BlueJ
![]() Share with a Friend |
Java Programs - Electricity Bill Calculation Using Slabs
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 ElectricityBill {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter total units consumed: ");
int units = sc.nextInt();
double billAmount = 0;
double meterRent = 500;
if (units <= 100) {
billAmount = units * 0.80;
}
else if (units <= 300) {
billAmount = (100 * 0.80) + ((units - 100) * 1.00);
}
else {
billAmount = (100 * 0.80) + (200 * 1.00) + ((units - 300) * 2.50);
}
double totalBill = billAmount + meterRent;
System.out.println("\n--- Electricity Bill Details ---");
System.out.println("Units Consumed : " + units);
System.out.println("Energy Charges : Rs. " + billAmount);
System.out.println("Meter Rent : Rs. " + meterRent);
System.out.println("Total Bill : Rs. " + totalBill);
sc.close();
}
}
Output
Output 1 :
SAMPLE INPUT : Enter total units consumed: 80 SAMPLE OUTPUT : --- Electricity Bill Details --- Units Consumed : 80 Energy Charges : Rs. 64.0 Meter Rent : Rs. 500.0 Total Bill : Rs. 564.0Output 2 :
SAMPLE INPUT : Enter total units consumed: 250 SAMPLE OUTPUT : --- Electricity Bill Details --- Units Consumed : 250 Energy Charges : Rs. 230.0 Meter Rent : Rs. 500.0 Total Bill : Rs. 730.0Output 3 :
SAMPLE INPUT : Enter total units consumed: 400 SAMPLE OUTPUT : --- Electricity Bill Details --- Units Consumed : 400 Energy Charges : Rs. 530.0 Meter Rent : Rs. 500.0 Total Bill : Rs. 1030.0
Explanation
1. Input
- Accepts the total units consumed.
2. Slab-wise Calculation
- First 100 units
Charge = Units × 0.80
- Next 200 units
Charge = (100 × 0.80) + (Remaining Units × 1.00)
- Above 300 units
Charge = (100 × 0.80) + (200 × 1.00) + (Remaining Units × 2.50)
3. Meter Rent
- A fixed charge of Rs. 500 is added.
4. Final Bill
Total Bill = Energy Charges + Meter Rent
