Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- /*Name: Brian D. Walton
- * Course: CSIS 161 Programming
- * Section: 01
- * Professor: Abuhejleh
- * Meets: 09:9:50 MWF
- * Given the amount to be deposited, the number of years, and interest rate,
- * this GUI java program will compute the amount of a certificate of deposit on maturity.
- */
- public class MaturityValue {
- public static class Maturity extends JFrame
- {
- private JLabel depositL, yearsL,
- rateL, valueL;
- private JTextField depositTF, yearsTF,rateTF, valueTF;
- private JButton calculateB, exitB;
- private CalculateButtonHandler cbHandler;
- private ExitButtonHandler ebHandler;
- private static final int WIDTH = 400;
- private static final int HEIGHT = 300;
- public Maturity ()
- {
- // Create four labels
- depositL = new JLabel("Amount deposited: ",
- SwingConstants.RIGHT);
- yearsL = new JLabel("Duration in years: ",
- SwingConstants.RIGHT);
- rateL = new JLabel("Interest Rate: ",SwingConstants.RIGHT);
- valueL = new JLabel("Value on Maturity: ",
- SwingConstants.RIGHT);
- //Create four textfields
- depositTF = new JTextField(10);
- yearsTF = new JTextField(10);
- rateTF = new JTextField(10);
- valueTF = new JTextField(10);
- //create Calculate Button
- calculateB = new JButton("Calculate");
- cbHandler = new CalculateButtonHandler();
- calculateB.addActionListener(cbHandler);
- //calculate button you are making the program listen to it.
- //Create Exit Button
- exitB = new JButton("Exit");
- ebHandler = new ExitButtonHandler();
- exitB.addActionListener(ebHandler);
- //Set the title of the window
- setTitle("Value of Certificate of Deposit");
- //Get the container
- Container pane = getContentPane();
- //Set the layout
- pane.setLayout(new GridLayout(5,2));
- //Place all items created
- pane.add(depositL);
- pane.add(depositTF);
- pane.add(yearsL);
- pane.add(yearsTF);
- pane.add(rateL);
- pane.add(rateTF);
- pane.add(valueL);
- pane.add(valueTF);
- pane.add(calculateB);
- pane.add(exitB);
- //set the size of the window and display it
- setSize(WIDTH,HEIGHT);
- setVisible(true);
- setDefaultCloseOperation(EXIT_ON_CLOSE);
- }
- private class CalculateButtonHandler implements ActionListener
- {
- public void actionPerformed(ActionEvent e)
- {
- double deposit, years, rate, value;
- deposit = Double.parseDouble(depositTF.getText());
- years = Double.parseDouble(yearsTF.getText());
- rate = Double.parseDouble(rateTF.getText());
- rate= 1 + (rate/100);
- rate= Math.pow(rate,years);
- value = deposit * rate;
- rateTF.setText("" + rate);
- valueTF.setText("" + value);
- }
- }
- private class ExitButtonHandler implements ActionListener
- {
- public void actionPerformed(ActionEvent e)
- {
- System.exit(0);
- }
- }
- public static void main(String[] args)
- {
- /*Maturity rectObject = new Maturity ();
- */
- }
- }//end of maturity
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement