investment calculator


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: investment calculator

  1. #1
    Join Date
    Sep 2005
    Posts
    11

    investment calculator

    Hi,
    I've started working on a college assignment but I am hoping to get some help along the way on my journey. I thought if someone could add to my program, then I could go off and work on it then if I get stuck again I could repost the revised code.

    This is some of the instruction I have been given:
    There are formulae to calculate the accumulated investment value of a series of regular payments and if you are familiar with these you may use them. However, since this program is to be written in an object oriented language (Java) it is sensible to consider any stream of regular annual payments as the sum of a sequence of single payments.

    Here is what I have done so far:

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.*;

    public class IC extends JFrame
    {
    // private RectanglePanel panel;
    private JLabel sampleField;
    private JCheckBox italicCheckBox;
    private JCheckBox boldCheckBox;
    private JRadioButton smallButton;
    private JRadioButton mediumButton;
    private JRadioButton largeButton;
    private JComboBox whetherCombo;
    private JComboBox facenameCombo;

    public IC()
    {
    MenuItemListener menuItemListener = new MenuItemListener();
    RadioButtonListener radioButtonListener = new RadioButtonListener(this);
    CheckBoxListener checkBoxListener = new CheckBoxListener(this);
    // construct components
    sampleField = new JLabel("Investment Calculator ");
    JPanel controlPanel = getControlPanel(radioButtonListener,
    checkBoxListener);

    // JFrame code
    JMenuBar menuBar = new JMenuBar();
    menuBar.add(createFileMenu(menuItemListener));
    menuBar.add(createEditMenu());
    setJMenuBar(menuBar);
    getContentPane().add(sampleField, BorderLayout.NORTH);
    getContentPane().add(controlPanel, BorderLayout.CENTER);
    pack();
    setLocation(200,200);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setVisible(true);
    }

    // public static void main(String[] args)
    // {
    // Payment p1 = new Payment(1000, 0);
    // Payment p2 = new Payment(1000, 1);
    // Payment p3 = new Payment(1000, 2);
    // PaymentSeries ps = new PaymentSeries();
    // //more code to add the payments to the PaymentSeries
    // System.out.println("Value is " + p3.getValue(7, 0.08));
    // JFrame appFrame = new InvestorAppFrame();
    // appFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    // appFrame.setVisible(true);
    // }


    /**
    * Creates the File menu.
    * @return the menu
    */
    public JMenu createFileMenu(ActionListener l)
    {
    JMenu menu = new JMenu("File");
    JMenuItem newItem = new JMenuItem("New");
    JMenuItem exportItem = new JMenuItem("Export");
    JMenuItem exitItem = new JMenuItem("Exit");
    newItem.setActionCommand("new");
    exportItem.setActionCommand("export");
    exitItem.setActionCommand("exit");
    newItem.addActionListener(l);
    exportItem.addActionListener(l);
    exitItem.addActionListener(l);
    menu.add(newItem);
    menu.add(exportItem);
    menu.add(exitItem);
    return menu;
    }

    public JMenu createEditMenu()
    {
    JMenu menu = new JMenu("Edit");
    return menu;
    }

    public JPanel getControlPanel(ActionListener rbl, ActionListener cbl)
    {
    JPanel whetherPanel = createComboBox();
    JPanel amountGroupPanel = createTextField(cbl);
    JPanel amountGroupPanel = createTextField02(cbl);
    // layout
    JPanel controlPanel = new JPanel();
    controlPanel.setLayout(new GridLayout(0, 1)); // single column
    controlPanel.add(whetherPanel);
    controlPanel.add(amountGroupPanel);
    controlPanel.add(interestGroupPanel);
    controlPanel.setBorder(new TitledBorder(
    new EtchedBorder(),
    "Is the investment is for a single initial " +
    "payment or a regular annual payment."));

    return controlPanel;
    }

    /**
    * Creates the combo box.
    * @return the panel containing the combo box
    */
    public JPanel createComboBox()
    {
    whetherCombo = new JComboBox();
    whetherCombo.addItem("single initial payment");
    whetherCombo.addItem("regular annual payment");
    whetherCombo.setEditable(false);
    whetherCombo.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent e)
    {
    JComboBox cb = (JComboBox)e.getSource();
    String s = (String)cb.getSelectedItem();
    System.out.println("s = " + s);
    }
    });

    JPanel panel = new JPanel();
    panel.add(whetherCombo);
    return panel;
    }

    /**
    * Creates a text field
    * @return the panel containing the text field
    */
    public JPanel createTextField(ActionListener l)
    {

    final JTextField xField = new JTextField(5);
    xField.addActionListener(l);
    JLabel xLabel = new Jlabel("$");


    JPanel panel = new JPanel();
    panel.add(xLabel);
    panel.add(xField);
    panel.setBorder(new TitledBorder(
    new EtchedBorder(),
    "How much money would you like to invest?"));
    return panel;
    }

    /**
    * Creates a text field
    * @return the panel containing the text field
    */
    public JPanel createTextField02(ActionListener 2)
    {

    final JTextField yField = new JTextField(5);
    yField.addActionListener(l);
    JLabel yLabel = new Jlabel("years")


    JPanel panel = new JPanel();
    panel.add(yField);
    panel.add(yLabel);
    panel.setBorder(new TitledBorder(
    new EtchedBorder(),
    "What is the duration of the investment in years?"));
    return panel;
    }

    /**
    * Gets user choice .
    *
    */


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

    class MenuItemListener implements ActionListener
    {
    public void actionPerformed(ActionEvent event)
    {
    JMenuItem item = (JMenuItem)event.getSource();
    String ac = item.getActionCommand();
    System.out.println("menu ac = " + ac);
    if(ac.equals("new"))
    ;
    if(ac.equals("export"))
    ;
    if(ac.equals("exit"))
    System.exit(0);
    }
    }

    class RadioButtonListener implements ActionListener
    {
    IC ic;

    public RadioButtonListener(IC ic)
    {
    this.ic = ic;
    }

    public void actionPerformed(ActionEvent e)
    {
    JRadioButton rb = (JRadioButton)e.getSource();
    String ac = rb.getActionCommand();
    System.out.println("rb ac = " + ac);

    }
    }

    class CheckBoxListener implements ActionListener
    {
    IC ic;

    public CheckBoxListener(IC ic)
    {
    this.ic = ic;
    }

    public void actionPerformed(ActionEvent e)
    {
    JCheckBox cb = (JCheckBox)e.getSource();
    String ac = cb.getActionCommand();
    System.out.println("cb ac = " + ac);

    }
    }

  2. #2
    Join Date
    Mar 2004
    Posts
    635
    You haven't stated what your problem is

Similar Threads

  1. investment calculator
    By Mrnewbie in forum Java
    Replies: 1
    Last Post: 10-25-2005, 11:45 AM
  2. Mortgage calculator help
    By vwrado in forum Java
    Replies: 1
    Last Post: 09-26-2005, 06:09 PM
  3. Mortgage Calculator Help
    By vwrado in forum Java
    Replies: 7
    Last Post: 09-06-2005, 06:06 PM
  4. Creating a calculator
    By sonict in forum Java
    Replies: 4
    Last Post: 05-16-2005, 06:19 PM
  5. Calculator
    By Chris in forum VB Classic
    Replies: 1
    Last Post: 04-11-2001, 09:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center