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



- First 100 units: $0.10 per unit
- Next 200 units (101 to 300): $0.15 per unit
- 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;
}