JAVA : The Calculation of Electricity Bill using JAVA

Java is a high-level programming language originally developed by Sun Microsystems and released in 1995. Java runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX. This tutorial gives a complete understanding of Java. This reference will take you through simple and practical approaches while learning Java Programming language.

Java program to calculate Electricity bill

If you wondering on how to calculate Electricity bill by writing the Java program there you go. Here we share the list of code with sample outputs, in five different ways using static values, using function or method, using command line arguments, do while, for loop, user define method along with sample outputs for each program.

Java Coding

public class EB extends javax.swing.JFrame {
public EB() {
        initComponents();
    }
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
int unit,amount;
unit = Integer.parseInt(jTextField1.getText());
if (unit<=100)
{
amount = unit*0;
jTextField2.setText(Integer.toString(amount));
}
else if (unit>100 && unit<=200)
{
amount = unit*3;
jTextField2.setText(Integer.toString(amount));
}
    }  
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new EB().setVisible(true);
            }
        });
    }
private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
}

Comments