Home Java Electricity Bill Calculation using Java Application

Electricity Bill Calculation using Java Application

1 min read
0
0
288

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;
    }

 

 

 

 

Load More Related Articles
Load More By admin
Load More In Java

Leave a Reply

Your email address will not be published. Required fields are marked *

Check Also

Enhancing Inventory Management with a POS System and PHP Queries

Introduction to Inventory Management with POS Systems Efficient inventory management is cr…