Project Question: Electricity Bill Calculator
☰Fullscreen
Table of Content:
Objective:
Develop a Java application that calculates and displays the electricity bill for a customer based on their meter readings. The application should validate input data, perform necessary calculations, and display the bill details in a formatted manner.
Requirements:
-
Input Data:
- Customer Number (String)
- Customer Name (String)
- Old Meter Reading (Integer)
- Current Meter Reading (Integer)
- Fixed Rental and Line Maintenance Charges (Constant: Rs. 250)
-
Validation:
- Ensure the old meter reading is not greater than the current meter reading.
- If invalid data is detected, display an error message and terminate the program.
-
Calculations:
- Calculate the total units consumed:
unitsUsed = currentReading - oldReading
. - Calculate the usage amount based on the units consumed:
- If
unitsUsed
is less than or equal to 100 units,userAmount = unitsUsed * 3.25
. - If
unitsUsed
is greater than 100 units,userAmount = 325 + ((unitsUsed - 100) * 4.75)
.
- If
- Calculate the tax (11.5% of the usage amount):
tax = userAmount * 11.5 / 100
. - Calculate the total bill:
bill = RENTAL_AMOUNT + userAmount + tax
.
- Calculate the total units consumed:
-
Output:
- Display the bill details including:
- Customer Number
- Customer Name
- Old Meter Reading
- Current Meter Reading
- Total Units Consumed
- Fixed Rental and Line Maintenance Charges
- Total Usage Amount
- Tax
- Total Bill Amount Payable
- Display the bill details including:
Sample Output:
WEST BENGAL BIJLI VITRAN LIMITED A GOVT. OF HARYANA UNDERTAKING Customer Number: hg654 Customer Name: Rumman Ansari Old Meter Reading: 2562 Current Meter Reading: 2892 Total Units Consumed: 330 Fixed Rental & Line Maintenance Charges: Rs.250 Total usage: Rs.1067 Tax (11.5%): Rs.123 ------------------------------------- Total Bill Amount Payable: Rs.1440
Implementation Steps:
-
Setup the Development Environment:
- Install a Java Development Kit (JDK) if not already installed.
- Use an Integrated Development Environment (IDE) like Eclipse or IntelliJ IDEA.
-
Define the Class:
- Create a class
ElectricityBill
with themain
method.
- Create a class
-
Implement Input Handling:
- Declare variables for customer details and meter readings.
- Initialize sample data for the purpose of this project.
-
Add Validation Logic:
- Check if the old meter reading is greater than the current meter reading.
-
Implement Calculation Logic:
- Calculate
unitsUsed
,userAmount
,tax
, andbill
as per the given logic.
- Calculate
-
Display the Bill:
- Use
System.out.println
to print the bill details in a formatted manner.
- Use
-
Test the Application:
- Run the program with different inputs to ensure it works correctly and handles errors as expected.
Extension Ideas:
- Allow user input via the console instead of using hardcoded sample data.
- Add functionality to read input from a file and write the output to a file.
- Implement a graphical user interface (GUI) for a better user experience.
This project will help you understand basic Java programming concepts, including input validation, arithmetic operations, conditional statements, and formatted output.