Project Question: Electricity Bill Calculator

Rumman Ansari   Software Engineer   2024-08-06 07:25:10   108  Share
Subject Syllabus DetailsSubject Details
☰ TContent
☰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:

  1. 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)
  2. 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.
  3. 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).
    • Calculate the tax (11.5% of the usage amount): tax = userAmount * 11.5 / 100.
    • Calculate the total bill: bill = RENTAL_AMOUNT + userAmount + tax.
  4. 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

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:

  1. 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.
  2. Define the Class:

    • Create a class ElectricityBill with the main method.
  3. Implement Input Handling:

    • Declare variables for customer details and meter readings.
    • Initialize sample data for the purpose of this project.
  4. Add Validation Logic:

    • Check if the old meter reading is greater than the current meter reading.
  5. Implement Calculation Logic:

    • Calculate unitsUsed, userAmount, tax, and bill as per the given logic.
  6. Display the Bill:

    • Use System.out.println to print the bill details in a formatted manner.
  7. 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.