Mr. Sharma designs interest calculator for compound interest and amount due in Java NetBeans.

Q23. Mr. Sharma of ICICI Bank frequently needs to calculate the interest and amount due for his clients. He asks his software programmer to design an interest calculator which will calculate the compound interest and amount due. The bank offer two different accounts fixed deposit and recurring deposit with different rate criteria. The programmer uses Java language with NetBeans IDE to develop this:

There is a JPanel containers which is used for Account Type:

• jRadioButton1 : Fixed Deposit(optFD) with buttonGroup1.
• jRadioButton2 : Recurring Deposit(optRD) with buttonGroup1.

and a jCheckBox1 control for Sr.Citizen(chkSR).

In the data entry form enter Principal(txtPrincipal),Time(txtTime),select an account type and/or Sr. Citizen and write the code for the following :

1. Write the code to disable the text boxes Interest(txtInterest),Amount(txtAmount), Rate(txtRate) in the form when the form activated.
2. Write the code for Exit and Clear Button to clear all the text boxes and check box. Set the default choice in the option button as Fixed Deposit.
3. Write the code for Calculate button to calculate compound interest and amount and display the values in text boxes: txtInterest and txtAmount depending on the principal, rate and time.

Note that the compound interest is calculated as principal*(1+rate/100)^Time & amount as Principal + Interest.

Rate is calculated based on the time according to the following table:

 Account Time(in yrs) Rate Fixed Deposit <=1 10 % >1 and <=5 12 % >5 15 % Recurring Deposit <=2 10 % >2 and <=7 12 % >7 15 %

An additional rate of 2% is given to senior citizens, i.e., if the chkSR CheckBox is checked.

Solution:

Code on Load Frame(Right click on frame then event then window then window is opened):

private void formWindowOpened(java.awt.event.WindowEvent evt) {

txtInterest.setEnabled(false);

txtAmount.setEnabled(false);

txtRate.setEnabled(false);

}

Code for Clear Button:

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {

txtPrincipal.setText(“”);

txtTime.setText(“”);

txtRate.setText(“”);

txtInterest.setText(“”);

txtAmount.setText(“”);

chkSR.setSelected(false);

optFD.setSelected(true);

}

Code for Exit Button:

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {

System.exit(0);

}

Code for Calculate Button:

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

double prin=Double.parseDouble(txtPrincipal.getText());

int time=Integer.parseInt(txtTime.getText());

double rate,ci,amt;

if(optFD.isSelected())

{

if(time<=1)

rate=10;

else if(time<=5)

rate=12;

else

rate=15;

}

else

{

if(time<=2)

rate=10;

else if(time<=7)

rate=12;

else

rate=15;

}

if(chkSR.isSelected())

rate=rate+2;

txtRate.setText(Double.toString(rate)+”%”);

ci=prin*Math.pow((1+rate/100),time);

txtInterest.setText(Double.toString(ci));

amt=ci+prin;

txtAmount.setText(Double.toString(amt));

}

Output:

167 Views