Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Problem in implementing mortgage calculator

  1. #1
    Junior Member
    Join Date
    Mar 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Problem in implementing mortgage calculator

    Right now I am supposed to create a mortgage calculator that would allow the user to select a length and interest, and then output the payment amount. The second step is to output how much of the loan is payed off each month, and then allowing the user to scroll through the list of months and amounts payed off.

    So far, I have the calculations working, I just need to get the list working.

    /****************************************************************/
    /*                      MortgageCalc2	                            */
    /*                                                              */
    /****************************************************************/
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class MortgageCalc2 extends JFrame
    {
    	private double interest = 5.75;
    	private double length = 30;
    	private JLabel jLabel1;
    	private JRadioButton ibutton1;
    	private JRadioButton ibutton2;
    	private JRadioButton ibutton3;
    	private JTextField field_amount;
    	private JTextField field_paymentamount;
    	private JTextField field_paymentdisplay;
    	private JButton button_calculate;
    	private JButton button_clear;
    	private JPanel contentPane;
    	private ButtonGroup interestselect;
     
     
    	public MortgageCalc2()
    	{
    		super();
    		initializeComponent();
     
    		this.setVisible(true);
    	}
     
    	private void initializeComponent()
    	{
    		jLabel1 = new JLabel();
    		ibutton1 = new JRadioButton();
    		ibutton2 = new JRadioButton();
    		ibutton3 = new JRadioButton();
    		field_amount = new JTextField();
    		field_paymentamount = new JTextField();
    		JTextArea field_paymentdisplay = new JTextArea();
    		button_calculate = new JButton();
    		button_clear = new JButton();
    		contentPane = (JPanel)this.getContentPane();
    		interestselect = new ButtonGroup();
     
    		jLabel1.setText("Mortgage Amount:");
     
    		ibutton1.setText("5 Year at 5.35% interest");
    		ibutton1.addItemListener(new ItemListener() {
    			public void itemStateChanged(ItemEvent e)
    			{
    				interest = 5.35;
    				length = 7;
    			}
     
    		});
     
    		ibutton2.setText("15 Year at 5.5% interest");
    		ibutton2.addItemListener(new ItemListener() {
    			public void itemStateChanged(ItemEvent e)
    			{
    				interest = 5.5;
    				length = 15;
    			}
     
    		});
     
    		ibutton3.setText("30 Year at 5.75% Interest");
    		ibutton3.setSelected(true);
    		ibutton3.addItemListener(new ItemListener() {
    			public void itemStateChanged(ItemEvent e)
    			{
    				interest = 5.75;
    				length = 30;
    			}
     
    		});
    		field_amount.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e)
    			{
    				field_amount_actionPerformed(e);
    			}
     
    		});
    		field_paymentamount.setText("-Monthly Payment Amount-");
    		field_paymentamount.setEditable(false);
    		field_paymentamount.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e)
    			{
    				field_paymentamount_actionPerformed(e);
    			}
     
    		});
    		field_paymentdisplay.setText(" ");
    		button_calculate.setText("Calculate");
    		button_calculate.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e)
    			{
    				button_calculate_actionPerformed(e);
    			}
     
    		});
    		button_clear.setText("Clear");
    		button_clear.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e)
    			{
    				button_clear_actionPerformed(e);
    			}
     
    		});
     
    		contentPane.setLayout(null);
    		addComponent(contentPane, jLabel1, 13,10,95,18);
    		addComponent(contentPane, ibutton1, 14,69,143,24);
    		addComponent(contentPane, ibutton2, 14,92,143,24);
    		addComponent(contentPane, ibutton3, 13,114,149,24);
    		addComponent(contentPane, field_amount, 12,31,100,22);
    		addComponent(contentPane, field_paymentamount, 15,154,134,22);
    		addComponent(contentPane, field_paymentdisplay, 175,21,190,184);
    		addComponent(contentPane, button_calculate, 14,223,83,28);
    		addComponent(contentPane, button_clear, 103,223,83,28);
    		interestselect.add(ibutton2);
    		interestselect.add(ibutton1);
    		interestselect.add(ibutton3);
    		this.setTitle("MortgageCalc2 - extends JFrame");
    		this.setLocation(new Point(0, 0));
    		this.setSize(new Dimension(390, 300));
    	}
     
    	private void addComponent(Container container,Component c,int x,int y,int width,int height)
    	{
    		c.setBounds(x,y,width,height);
    		container.add(c);
    	}
     
    	private void button_calculate_actionPerformed(ActionEvent e)
    	{
    		System.out.println("\nbutton_calculate_actionPerformed(ActionEvent e) called.");
     
     
    				String amount1 = field_amount.getText();
    				Float amount = new Float(amount1);
     
    				double j = ( interest / ( 12 * 100 ) ) ;
    				double n = ( length * 12 );
     
    				double payment = ( amount * ( j / ( 1 - Math.pow( ( 1 + j ), -n ))));
    				String payment2 = Double.toString(payment);
    				field_paymentamount.setText(payment2);
     
    				double paymentadd = 0;
    				double paymentcount = 0;
     
    				while (paymentadd<amount) {
    				paymentadd = paymentadd + payment;
    				paymentcount = paymentcount + 1;
    				String doublepaymentadd1 = Double.toString(paymentadd);
    				String doublepaymentcount1 = Double.toString(paymentcount);
    				JTextArea.insert(doublepaymentadd1, doublepaymentcount1);
     
    				}
    	}
     
    	private void button_clear_actionPerformed(ActionEvent e)
    	{
    		System.out.println("\nbutton_clear_actionPerformed(ActionEvent e) called.");
     
    	}
    }

    Basically, in the large box to the right, I would like it too look like this:

    1 AMOUNT
    2 AMOUNT * 2
    3 amount * 3

    or

    1 $100
    2 $200
    3 $400

    If anyone could help me, that would be great.


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Printing to a text area

    Hello American Raptor and welcome to the forums.

    I can't seem to compile this code. Is this the full code?
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

Similar Threads

  1. Printing a Histogram Help - Arrays
    By Mock26 in forum Collections and Generics
    Replies: 1
    Last Post: June 4th, 2009, 04:49 AM
  2. How to format text in java?
    By fourseven in forum Java Theory & Questions
    Replies: 3
    Last Post: May 16th, 2009, 09:42 PM
  3. Java program to reduce spaces between the words in a text file
    By tyolu in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: May 13th, 2009, 07:17 AM
  4. [SOLVED] Enhancement in program of removing whitespace from text file
    By John in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: April 27th, 2009, 09:36 AM
  5. How to read character from image area(jpg image)?
    By sundarjothi in forum Java Theory & Questions
    Replies: 5
    Last Post: August 6th, 2008, 02:08 AM