Java

Moderators: zibadian
Number of threads: 7832
Number of posts: 18231

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Java - Mortgage Calculator Posted by TBRown12 on 7 Feb 2012 at 8:08 PM
Hello All!

I've been racking my brain for days trying to figure out how to get a Mortgage Calculator to run (getting input from user for interest rate, loan term and loan amount). The code I have is the basis on the rest of the program that I have to write. I am probably over thinking it but ANY help would be great!



import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;

import javax.swing.*;



public class Tasha2Week1{


//Creates Fields
JTextField AnnualPercentageRate = new JTextField();
JTextField TermInYears = new JTextField();
JTextField LoanAmount = new JTextField();
JTextArea Output = new JTextArea();

public static void main(String[] args) {
Tasha2Week1 Tasha2Week1 = new Tasha2Week1();
}
//Code for the Exit Button
private void jButtonQuitActionPerformed(java.awt.event.ActionEvent evt){// Code entered here will be run when the Quit button is clicked
System.exit(0);
}
//Code for the Clear Button
private void jButtonClearActionPerformed(java.awt.event.ActionEvent evt){
//Clear ALL fields
AnnualPercentageRate.setText("");
TermInYears.setText("");
LoanAmount.setText("");
Output.setText("");
}
//Code for the Enter Button
public void PaymentCalculator(){
}

private void jButtonCalculateActionPerformed(java.awt.event.ActionEvent evt){
//Enter Calculator

DecimalFormat formatNumber = new DecimalFormat("$#,###.##");

double LoanAMT = Double.parseDouble(LoanAmount.getText());
double LoanTERM = Double.parseDouble(TermInYears.getText());
double LoanRATE = Double.parseDouble(AnnualPercentageRate.getText());
double Payment = LoanAMT*Math.pow(1+LoanRATE, LoanTERM)*LoanRATE/(Math.pow(1+LoanRATE, LoanTERM)-1);


Output.setText(formatNumber.format(Payment));

}


public Tasha2Week1(){
//GUI LAYOUT
JFrame jf = new JFrame();
jf.setTitle("Mortgage Calculator"); //Sets Title
jf.setSize(800, 500); //Set Size
jf.setVisible(true);

//GUI Objects
Container pane=jf.getContentPane();
JLabel l1 = new JLabel ("Please insert Interest Rate here: ");
JLabel l2 = new JLabel ("Please insert Loan Amount here: ");
JLabel l3 = new JLabel ("Please insert Loan Term in years here: ");

JButton Calculate = new JButton("Calculate");
JButton Quit = new JButton("Quit");
JButton Clear = new JButton("Clear");

JScrollPane scrollPane = new JScrollPane(Output);

pane.setLayout(null);
l1.setBounds(5, 20, 295, 15);
l2.setBounds(5, 120, 295, 15);
l3.setBounds(5, 220, 295, 15);

Calculate.setBounds(650,25,100, 20);
Clear.setBounds(650, 50,100, 20);
Quit.setBounds(650, 75,100, 20);
Output.setBounds(5, 300, 775,150);
scrollPane.setBounds(5,300,775,150);

pane.add(l1);
pane.add(AnnualPercentageRate);
pane.add(l2);
pane.add(LoanAmount);
pane.add(l3);
pane.add(TermInYears);

AnnualPercentageRate.setBounds(300, 20, 300, 20); // Sets loanfield, termfield, interestfield position on the panel
LoanAmount.setBounds(300, 120, 300, 20);
TermInYears.setBounds(300, 220, 300, 20);

pane.add(Calculate);
pane.add(Quit);
pane.add(Clear);
pane.add(Output);

jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setVisible(true);

Quit.addActionListener(new ActionListener(){
@Override
public void actionPerformed(java.awt.event.ActionEvent evt){
jButtonQuitActionPerformed(evt);
}
});
Calculate.addActionListener(new ActionListener(){
@Override
public void actionPerformed(java.awt.event.ActionEvent evt){
jButtonCalculateActionPerformed(evt);
}
});
Clear.addActionListener(new ActionListener(){
@Override
public void actionPerformed(java.awt.event.ActionEvent evt){
jButtonClearActionPerformed(evt);
}
});





}


}
Report
Re: Java - Mortgage Calculator Posted by jewel86 on 12 Feb 2012 at 8:17 PM
i think it's good ^^ thanks for sharing ^^

thesimpsons
csstips.org
Report
Re: Java - Mortgage Calculator Posted by jewel86 on 12 Feb 2012 at 8:20 PM
i think it's good ^^ thanks for sharing ^^



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.