Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.82 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4.     /*Name: Brian D. Walton
  5.     * Course: CSIS 161 Programming
  6.     * Section: 01
  7.     * Professor: Abuhejleh
  8.     * Meets: 09:9:50 MWF
  9.     * Given the amount to be deposited, the number of years, and interest rate,
  10.     * this GUI java program will compute the amount of a certificate of deposit on maturity.
  11.     */
  12. public class MaturityValue {
  13.    
  14. public static class Maturity  extends JFrame
  15.     {
  16.         private JLabel depositL, yearsL,
  17.                rateL, valueL;
  18.         private JTextField depositTF, yearsTF,rateTF, valueTF;
  19.  
  20.         private JButton calculateB, exitB;
  21.  
  22.         private CalculateButtonHandler cbHandler;
  23.  
  24.         private ExitButtonHandler ebHandler;
  25.  
  26.         private static final int WIDTH = 400;
  27.         private static final int HEIGHT = 300;
  28.  
  29.  
  30.         public Maturity ()
  31.         {
  32.                             // Create four labels
  33.                 depositL = new JLabel("Amount deposited: ",
  34.                                       SwingConstants.RIGHT);
  35.                 yearsL = new JLabel("Duration in years: ",
  36.                                          SwingConstants.RIGHT);
  37.                 rateL = new JLabel("Interest Rate: ",SwingConstants.RIGHT);
  38.                 valueL = new JLabel("Value on Maturity: ",
  39.                                             SwingConstants.RIGHT);
  40.  
  41.                               //Create four textfields
  42.                 depositTF = new JTextField(10);
  43.                 yearsTF = new JTextField(10);
  44.                 rateTF = new JTextField(10);
  45.                 valueTF = new JTextField(10);
  46.  
  47.                               //create Calculate Button
  48.                 calculateB = new JButton("Calculate");
  49.                 cbHandler = new CalculateButtonHandler();
  50.                 calculateB.addActionListener(cbHandler);
  51.                 //calculate button you are making the program listen to it.
  52.                               //Create Exit Button
  53.                 exitB = new JButton("Exit");
  54.                 ebHandler = new ExitButtonHandler();
  55.                 exitB.addActionListener(ebHandler);
  56.  
  57.                 //Set the title of the window
  58.                 setTitle("Value of Certificate of Deposit");
  59.  
  60.                 //Get the container
  61.                 Container pane = getContentPane();
  62.  
  63.                 //Set the layout
  64.             pane.setLayout(new GridLayout(5,2));
  65.  
  66.              //Place all items created
  67.                 pane.add(depositL);
  68.                 pane.add(depositTF);
  69.                 pane.add(yearsL);
  70.                 pane.add(yearsTF);
  71.                 pane.add(rateL);
  72.                 pane.add(rateTF);
  73.                 pane.add(valueL);
  74.                 pane.add(valueTF);
  75.                 pane.add(calculateB);
  76.                 pane.add(exitB);
  77.  
  78.                             //set the size of the window and display it
  79.                 setSize(WIDTH,HEIGHT);
  80.                 setVisible(true);
  81.                     setDefaultCloseOperation(EXIT_ON_CLOSE);
  82.         }
  83.  
  84.         private class CalculateButtonHandler implements ActionListener
  85.         {
  86.                 public void actionPerformed(ActionEvent e)
  87.                 {
  88.                     double deposit, years, rate, value;
  89.  
  90.                     deposit = Double.parseDouble(depositTF.getText());
  91.                     years = Double.parseDouble(yearsTF.getText());
  92.                     rate = Double.parseDouble(rateTF.getText());
  93.                     rate= 1 + (rate/100);
  94.                     rate= Math.pow(rate,years);
  95.                     value = deposit * rate;
  96.  
  97.                     rateTF.setText("" + rate);
  98.                     valueTF.setText("" + value);
  99.                 }
  100.         }
  101.  
  102.         private class ExitButtonHandler implements ActionListener
  103.         {
  104.                 public void actionPerformed(ActionEvent e)
  105.                 {
  106.                         System.exit(0);
  107.                 }
  108.         }
  109.        
  110.     public static void main(String[] args)
  111.         {
  112.                 /*Maturity  rectObject = new Maturity ();
  113.                  */
  114.         }
  115.     }//end of maturity
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement