Write a GUI program to compute the amount of a certificate of deposit on maturit
ID: 3551655 • Letter: W
Question
Write a GUI program to compute the amount of a certificate of deposit on maturity. The sample data follows:
Amount deposited: 80000.00
Years: 15
Interest rate: 7.75
Hint: to solve this problem, compute 80000.00 (1 + 7.75 / 100)15
program should contain 4 rows by 2 columns of GUI components. They should be JLabels for displaying information and JTextFields for accepting input data from the user. Labels on the left column should be right-aligned; the result on the right column should be left-aligned
Explanation / Answer
mport java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class TotalAmount extends JFrame
{
TotalAmount(){
JLabel lab1=new JLabel("Amount");
final JTextField text1=new JTextField(20);
JLabel lab2=new JLabel("Rate of Interest");
final JTextField text2= new JTextField(20);
JLabel lab3=new JLabel("Time");
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());
double t=Double.parseDouble(text3.getText());
double v1=r/100;
double v2=1+v1;
double v3=Math.pow(v2,t);
double amount=p*v3;
JOptionPane.showMessageDialog(null, "Total Amount is: "+amount);
}
});
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,100,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 TotalAmount();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.