/** Mortgage Calculator **/
/** Brenda Harris **/
/** Prg421 **/
/** Jan 19 2009 **/
import java.swing.*;
import.java.awt.*;
import java.awt.event.*;
import java.awt.datatransfer.*;
import java.Math;
import java.text.DecimalFormat;
import javax.swingJOptionPane;
importnjavax.swing.ButtonGroup;
public class MortgageCalculatorServiceRequest extends JFrame
{
public static void main(String[]args)
{
new MortgageCalculatorServiceRequest()
{
//Declare buttons, text fields, and labels
private JButton calculate;
private JButton exit;
private JTextField enterAmount;
private JTextField enterInterest;
private JTextField enterMonth;
private JLabel Principle;
private JLabel interest;
private JLabel month rate;
private JLabel data;
private JLabel data1;
private JLabel data2;
private JRadioButton term30;
private JRadioButton term15;
private JRadioButton term7;
Date currentDate = newDate(); //Date constructor
// Define a decimal format for monetary values
double NumberOfYears,InterestRate,Principle,MonthlyPayment;
DecimalFormat dfMonetaryFormat = new DecimalFormat("$#,###.##");
//Define Program Variables needed for monthly payment calculation
InterestRate[0] = .0575; //*5.75% interest rate
NumberOfYears= 30.00; //*30 year
Principle = 200000.00; // *$200,000 Loan
MonthlyPayment = ((5.75/100/12)(30*12)*200000);
Interest rate[1] =.055; //5.5% interest rate
NumberOfYears= 15.00; //*15 year
Principle = 200000.00; // *$200,000 Loan
MonthlyPayment = ((.055/100/12)(15*12)*200000);
Interest rate[2] =.0535; //5.35% interest rate
NumberOfYears= 7.00; //*7 year
Principle = 200000.00; // *$200,000 Loan
MonthlyPayment = ((.0535/100/12)(7*12)*200000);
//Call Calculate monthly payment() Calculate the number of monthly payments.
MonthlyPayment = CalculateMonthlyPayment (Principle,InterestRate,NumberOfYears);
//Call CalculateInterestAmount= CalculateMonthlyInterest (MonthlyPayment, Principle, NumberOfYears);
//MonthlyPayment, MonthlyInterest,and Principal balance)
//Print out the values for the Principle balance, interest rate, and number of years.
//Display the Mortgage Payment amount, principle balance, interest rate for each mortgage payment for term of loan;
//Create the event listener
ClickListener click=new ClickListener();
// Create Action Listeners
calculate.addActionListener(click);
exit.addActionListener(click);
calc.addActionListener(click);
}
//begin the events
private class ClickListener implements ActionListener
public void actionPerformed(ActionEvent)
{
if (getSource() ==calc) //if user clicks the calculate button
{
try
{
//convert text into numbers
dfMonetaryFormat= enterAmount, getText();
//create the arrays for three different loans
int terms[] = (30, 15, 7);//loan in years
double InterestArray[]= 5.75, 5.55, 5.35);//interest as a percent
//Array 1
if (term30.is selected())
{
double InterestRate[0] = .0575; //*5.75% interest rate
double NumberOfYears= 30.00; //*30 year
double Principle = 200000.00; // *$200,000 Loan
double MonthlyPayment = ((5.75/100/12)(30*12)*200000);
//create number format
NumberFormat fixdecimal= NumberFormat,getNumberInstance();
fixdecimal.setMinimumFractionDigits(2);
fixdecimal.setMaximumFractionDigits(2);
//create counter
for (int x = 0; x <= term0; x++)
{
interestpay = (remainBal * interest0);
double interestout = 0;
remainBal = (remainBal - (payment - interestpay));
interestout = (interestout + interestpay);
// The output based on amount input and loan selection.
JOptionPane.showMessageDialog(null, "Original Balance = $" + receiveAmount +
"\nPayment #" + x + "\nMonthly Payment $" + fixdecimal.format(payment) +
"\nRemaining Balance $" + fixdecimal.format(remainBal) +
"\nInterest Paid $" + fixdecimal.format(interestpay),
"Payment History",
JOptionPane.showConfirmDialog(null, "Would you like to calculate a new amount?" + "\n\n(choose yes to continue or No to exit)"
JOptionPane,Yes_No_Option;
if (finalanswer==JOptionPane.No_Option
{
system.exit(0);
{
//if user chooses "yes" the amount field blanks out
enterAmount.setText(null);
}
//Array2
} else if (term15.isSelected())
{
double Interest rate[1] =.055; //5.5% interest rate
double NumberOfYears= 15.00; //*15 year
double Principle = 200000.00; // *$200,000 Loan
double MonthlyPayment = ((.055/100/12)(15*12)*200000);
//create the number format
NumberFormat fixdecimal = NumberFormat.getNumberInstance();
fixdecimal.setMinimumFractionDigits(2);
fixdecimal.setMaximumFractionDigits(2);
// Create counter
for (int x = 1; x <= term1; x++) {
interestpay = (remainBal * interest1);
double interestout = 0;
remainBal = (remainBal - (payment - interestpay));
interestout = (interestout + interestpay);
}
// The output based on amount input and loan selection.
JOptionPane.showMessageDialog(null, "Original Balance = $" + receiveAmount +
"\nPayment #" + x + "\nMonthly Payment $" + fixdecimal.format(payment) +
"\nRemaining Balance $" + fixdecimal.format(remainBal) +
"\nInterest Paid $" + fixdecimal.format(interestpay),
"Payment History",
JOptionPane.PLAIN_MESSAGE);
JOptionPane.showConfirmDialog(null, "Would you like to calculate a new amount?" + "\n\n(choose yes to continue or No to exit)"
JOptionPane,Yes_No_Option;
if (finalanswer==JOptionPane.No_Option
{
system.exit(0);
{
//if user chooses "yes" the amount field blanks out
enterAmount.setText(null);
//Array3
} else if (term7.isSelected())
{
double Interest rate[2] =.0535; //5.35% interest rate
double NumberOfYears= 7.00; //*7 year
double Principle = 200000.00; // *$200,000 Loan
double MonthlyPayment = ((.0535/100/12)(7*12)*200000);
// create the number format
NumberFormat fixdecimal = NumberFormat.getNumberInstance();
fixdecimal.setMinimumFractionDigits(2);
fixdecimal.setMaximumFractionDigits(2);
// Create counter
for (int x = 1; x <= term1; x++) {
interestpay = (remainBal * interest1);
double interestout = 0;
remainBal = (remainBal - (payment - interestpay));
interestout = (interestout + interestpay);
}
// The output based on amount input and loan selection.
JOptionPane.showMessageDialog(null, "Original Balance = $" + receiveAmount +
"\nPayment #" + x + "\nMonthly Payment $" + fixdecimal.format(payment) +
"\nRemaining Balance $" + fixdecimal.format(remainBal) +
"\nInterest Paid $" + fixdecimal.format(interestpay),
"Payment History",
JOptionPane.PLAIN_MESSAGE);
JOptionPane.showConfirmDialog(null, "Would you like to calculate a new amount?" + "\n\n(choose yes to continue or No to exit)"
JOptionPane,Yes_No_Option;
if (finalanswer==JOptionPane.No_Option
{
system.exit(0);
{
//if user chooses "yes" the amount field blanks out
enterAmount.setText(null);
}
}
}
catch (NumberFormatException)
{
}
}
// Create a new event
if (getSource() == calculate)
{
try {
// turn text entries into numbers
double receiveAmount = Double.parseDouble(enterAmount.getText());
double receivePerc = Double.parseDouble(enterInterest.getText());
double receiveTerm = Double.parseDouble(enterMonth.getText());
double receiveInterest = receivePerc;
double receiveTerms = receiveTerm;
double interest1 = (receiveInterest / (12 * 100));
double term1 = (receiveTerms * 12);
double term2 = (1 + interest1);
double pay1 = Math.pow(term2, -term1);
double payment = ((receiveAmount * interest1) / (1 - pay1));
double interestpay;
double remainBal = receiveAmount;
// create the number format
NumberFormat fixdecimal = NumberFormat.getNumberInstance();
fixdecimal.setMinimumFractionDigits(2);
fixdecimal.setMaximumFractionDigits(2);
// Create counter
for (int x = 1; x <= term1; x++)
{
interestpay = (remainBal * interest1);
double interestout = 0;
remainBal = (remainBal - (payment - interestpay));
interestout = (interestout + interestpay);
// The output based on amount input and loan selection.
JOptionPane.showMessageDialog(null, "Original Balance = $" + receiveAmount +
"\nPayment #" + x + "\nMonthly Payment $" + fixdecimal.format(payment) +
"\nRemaining Balance $" + fixdecimal.format(remainBal) +
"\nInterest Paid $" + fixdecimal.format(interestpay),
"Payment History",
JOptionPane.PLAIN_MESSAGE);
response = JOptionPane.showConfirmDialog(null,
"Would you like to calculate another payment?"
JOptionPane.YES_NO_OPTION);
//System.exit(0);//End Program
}
while(response == 0);
}
}
Java Code HelpI can not get this code to run
Page 1 of 1
5 Replies - 870 Views - Last Post: 26 January 2009 - 06:53 PM
#1
Java Code Help
Posted 26 January 2009 - 02:38 PM
Replies To: Java Code Help
#2
Re: Java Code Help
Posted 26 January 2009 - 02:40 PM
Please use code tags around your code..
[ code]code here[ /code] (without the blanks)
[ code]code here[ /code] (without the blanks)
This post has been edited by Gloin: 26 January 2009 - 02:41 PM
#3
Re: Java Code Help
Posted 26 January 2009 - 04:19 PM
Gloin, for future reference, the automatic post for that is...
: code : (No spaces)
That yields...
: code : (No spaces)
That yields...
This post has been edited by Locke: 26 January 2009 - 04:38 PM
#4
Re: Java Code Help
Posted 26 January 2009 - 04:23 PM
Oh man... Thank you so much.. it's a real pain writing that every time.. 
It's probably been there all the time too just I'm too blind to see it..
It's probably been there all the time too just I'm too blind to see it..
#5
Re: Java Code Help
Posted 26 January 2009 - 06:48 PM
Please describe the problem that you are having. Include a description of what you are trying to do. Include any error messages or unexpected output that you are receiving.
#6
Re: Java Code Help
Posted 26 January 2009 - 06:53 PM
Jayman, on 26 Jan, 2009 - 05:48 PM, said:
Please describe the problem that you are having. Include a description of what you are trying to do. Include any error messages or unexpected output that you are receiving.
And full Edit your first post to give a more descriptive title than Java Help Me
not very usefull on a Java forum where you help people with coding problem
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote






|