Showing posts with label Java Program to find compound interest compounded annually. Show all posts
Showing posts with label Java Program to find compound interest compounded annually. Show all posts

Monday, September 3, 2018

Java program to find compound interest compunded annully



Follow the steps to create GUI:

Step-1: Drag and drop the label from the Palette window and rename it as "Enter Principal".

Step-2: Drag and drop the TextField from the Palette window and give the variable name to   "txtPrincipal" by right-clicking on text field object.

Step-3: Drag and drop the label from the Palette window and rename it as "Enter Rate".

Step-4: Drag and drop the TextField from the Palette window and give the variable name to "txtRate".

Step-5: Drag and drop the label from the Palette window and rename it as "Enter Time".

Step-6: Drag and drop the TextField from the Palette window and give the variable name to "txtTime".

Step-7: Drag and drop the Button object from the Palette window and give the variable name to "btnCalculate" and change the text to "Calculate".

Step-8: Drag and drop the label from the Palette window and rename it as "Total Amount".

Step-9: Drag and drop the TextField from the Palette window and give the variable name to   "txtAmount" by right-clicking on text field object and make editable to false.

Step-10: Drag and drop the TextField from the Palette window and give the variable name to   "txtCI" by right-clicking on text field object and make editable to false.

Finally, double-click on the button and follow the codes given below:

 private void btnCalculateActionPerformed(java.awt.event.ActionEvent evt) {                                             
       double principal,rate;
       int time;
       principal=Double.parseDouble(txtPrincipalAmount.getText());
       rate=Double.parseDouble(txtRate.getText());
       time=Integer.parseInt(txtTime.getText());
       
       double amount=principal*Math.pow(1+rate/100,time);
       double ci=amount-principal;
       
       txtAmount.setText(Double.toString(amount));
       txtCI.setText(Double.toString(ci));
    }