Java

Electricity Bill Calculation using Java Application

This tutorils teach Electricity Bill Calculating based on the below conditions step by step

  1. First 100 units: $0.10 per unit
  2. Next 200 units (101 to 300): $0.15 per unit
  3. Above 300 units: $0.20 per unit

 

This is code of the project

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) 
{                                         
        int unitcal = Integer.parseInt(txtUnit.getText());
        double totalbill = calBill(unitcal);
        txtBill.setText(String.format(" $%.2f", totalbill));
}                                        

    int units;
    private static double calBill(int units)
    {
        double totbill = 0.0;
        
        if(units <= 100)
        {
            totbill = units * 0.10;
        }
        else if(units <= 300)
        {
            totbill = 100 * 0.10 + (units -100) * 0.15;
        }
        else
        {
             totbill = 100 * 0.10 +  200 * 0.15 + (units -300) * 0.25;
        }
        return totbill;
    }

 

 

 

 

admin

Share
Published by
admin

Recent Posts

Conditional Statements in Python

Conditional statements in Python allow us to control the flow of execution based on conditions.…

2 weeks ago

Java Beans

A Java Bean is a reusable software component that follows a specific set of conventions.…

3 weeks ago

Java String Methods

Java provides a rich set of built-in methods for handling String operations efficiently. Since strings…

3 weeks ago

Java Developer Jobs

Java remains one of the most in-demand programming languages worldwide, powering everything from enterprise applications…

3 weeks ago

Converting Integer to String in Java

Java provides multiple ways to convert an integer (int) to a string (String). Whether you're…

3 weeks ago

JSP to JSP Communication: A Complete Guide to Dynamic Java Web Development

Java Server Pages (JSP) is a powerful technology used to develop dynamic web applications by…

4 weeks ago