Answer to Question #201104 in Java | JSP | JSF for Hamza

Question #201104

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.


1
Expert's answer
2021-06-02T14:28:39-0400
import javax.swing.*;

public class GUI extends JFrame {

    public GUI() {
        JPanel panel = new JPanel();
        panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

        JLabel depositedAmountLabel = new JLabel("Amount deposited:");
        JLabel yearsLabel = new JLabel("Years:");
        JLabel interestRateLabel = new JLabel("Interest rate:");
        JLabel resultLabel = new JLabel("Enter the values.");

        JTextField depositedAmountField = new JTextField();
        JTextField yearsField = new JTextField();
        JTextField interestRateField = new JTextField();

        JButton calculateButton = new JButton("Calculate");
        calculateButton.addActionListener(actionEvent -> {
            try {
                double amount = Double.parseDouble(depositedAmountField.getText());
                int years = Integer.parseInt(yearsField.getText());
                double rate = Double.parseDouble(interestRateField.getText());
                resultLabel.setText("The result: " + (amount * (1 + rate / 100) * years));
            } catch (Exception e) {
            }
        });

        panel.add(depositedAmountLabel);
        panel.add(depositedAmountField);
        panel.add(yearsLabel);
        panel.add(yearsField);
        panel.add(interestRateLabel);
        panel.add(interestRateField);
        panel.add(resultLabel);
        panel.add(calculateButton);

        add(panel);
        setSize(250, 200);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setVisible(true);
    }

    public static void main(String[] args) {
        new GUI();
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS