- 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 8
Conditional Constructs in Java
Class 10 - Logix Kips ICSE Computer Applications with BlueJ
![]() Share with a Friend |
Java Program: To Calculate the Electricity Bill using Slab Rates
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 ElectricityBill {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int units;
double bill = 0;
System.out.print("Enter total units consumed: ");
units = sc.nextInt();
if (units <= 100) {
bill = units * 0.80;
} else if (units <= 300) {
bill = (100 * 0.80) + ((units - 100) * 1.00);
} else {
bill = (100 * 0.80) + (200 * 1.00) + ((units - 300) * 2.50);
}
// Add meter rent
bill = bill + 500;
System.out.println("Total Electricity Bill = Rs. " + bill);
}
}
Output
Sample Run Enter total units consumed: 350 Total Electricity Bill = Rs. 905.0
Calculation
- First 100 units → 100 × 0.80 = 80
- Next 200 units → 200 × 1.00 = 200
- Remaining 50 units → 50 × 2.50 = 125
- Energy charge = 405
- Meter rent = 500
- Total Bill = Rs. 905
📝 Explanation
- Units are taken as input using the Scanner class
- Slab-wise billing is applied using an if-else ladder
- Meter rent of Rs. 500 is added at the end
- The final bill is displayed in rupees
