
. Develop a program that accepts an initial amount of money (called the principal), a simple annual interest rate, and a number of months will compute the balance at the end of that time. Assume that no additional deposits or withdrawals are made and that a month is 1/12 of a year. Total interest is the product of the principal, the annual interest rate expressed as a decimal, and the number of years.

Hi Friend,
Try the following code:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class TotalInterest extends JFrame
{
TotalInterest(){
JLabel lab1=new JLabel("Principal");
final JTextField text1=new JTextField(20);
JLabel lab2=new JLabel("Rate of Interest");
final JTextField text2= new JTextField(20);
JLabel lab3=new JLabel("Number of Months");
final JTextField text3=new JTextField(20);
JButton b=new JButton("Get");
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
double p=Double.parseDouble(text1.getText());
double r=Double.parseDouble(text2.getText())/100;
double t=Double.parseDouble(text3.getText())/12;
double interest=p*r*t;
JOptionPane.showMessageDialog(null, "Total Interest is: "+interest);
}
});
setLayout(null);
lab1.setBounds(10,10,100,20);
text1.setBounds(150,10,200,20);
lab2.setBounds(10,40,100,20);
text2.setBounds(150,40,200,20);
lab3.setBounds(10,70,120,20);
text3.setBounds(150,70,200,20);
b.setBounds(150,110,70,20);
add(lab1);
add(text1);
add(lab2);
add(text2);
add(lab3);
add(text3);
add(b);
setVisible(true);
setSize(400,200);
}
public static void main(String[] args)
{
new TotalInterest();
}
}
Thanks
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.