# Need Help Finishing program

Page 1 of 1

## 0 Replies - 2934 Views - Last Post: 17 May 2005 - 06:39 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=11193&amp;s=607b7faacfb1fd825caf4110b4a6483d&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 12_MMth_99

Reputation: 0
• Posts: 1
• Joined: 17-May 05

# Need Help Finishing program

Posted 17 May 2005 - 06:39 PM

I am trying to finish up my mortgage calculator with the following information. If someone could let me know how and what I have to do to incorporate the following instructions into my program, I would be so ever grateful:

Add a field for the user to enter his annual salary. After the user has selected a mortgage and the monthly mortgage payment has been calculated, determine if the user "qualifies" for the loan by comparing 28% of the user's monthly salary to the mortgage payment amount. If 28% of the monthly salary equals or exceeds the mortgage payment, post the words "You qualify!" in large, bold, colored letters on the screen, and display a graphic of a house near the bottom of the screen. If 28% of the monthly salary is less than the mortgage payment, post the word "Sorry" in large, italic, black letters on the screen, and display a graphic of the international no symbol near the bottom of the screen.

Here is my code for reference:

[/CODE]
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import java.awt.*;
import java.awt.event.*;
import java.text.NumberFormat;
import java.text.*;
import java.util.*;
import java.io.*;
import java.text.DecimalFormat;

public class MikeFinalMorCalc extends JFrame implements ActionListener
{

JLabel AmountLabel = new JLabel(" Enter Mortgage Amount:\$ ");
JTextField mortgageAmount = new JTextField(10);

JLabel SalaryLabel = new JLabel(" Annual Salary:\$ ");
JTextField salaryAmount = new JTextField(10);
JButton sumAvg = new JButton("Summary Calculation");

JLabel PaymentLabel = new JLabel(" Monthly Payment: ");
JTextField monthlyPayment = new JTextField(10);

JLabel chosenPTlabel = new JLabel(" Chosen Term and interest Rate: ");
JTextField chosenPT = new JTextField(10);

JButton newcalcButton = new JButton("Reset values");

JTextArea mortgageTable = new JTextArea(10,35);
JScrollPane scroll = new JScrollPane(mortgageTable);

String term[];
String rate[];
int numRec;
double iInterestRate;
int iTermAmt;

public MikeFinalMorCalc()
{
super("MORTGAGE CALCULATOR");
fRecordCount();
term = new String[numRec];
rate = new String[numRec];

{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
});

for(int x=0; x < numRec; x++) {
menuChoice[x] = (term[x] + " Yrs" + " @ " + rate[x] + "%" );
}

{
public void actionPerformed (ActionEvent e) {

String mi = e.getActionCommand();
System.out.println(mi);

}
} );

{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
});

setSize(600, 400);
setLocation(200,200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel pane = new JPanel();
pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
Container grid = getContentPane();
grid.setLayout(new GridLayout(5,3));
grid.setBackground(Color.yellow);
setCursor(new Cursor(Cursor.HAND_CURSOR));

mortgageAmount.setBackground(Color.blue);
mortgageAmount.setForeground(Color.yellow);
mortgageAmount.setCaretColor(Color.white);
mortgageAmount.setFont(new Font("Times New Roman", Font.PLAIN, 18));

salaryAmount.setBackground(Color.blue);
salaryAmount.setForeground(Color.yellow);
salaryAmount.setCaretColor(Color.white);
salaryAmount.setFont(new Font("Times New Roman", Font.PLAIN, 18));

monthlyPayment.setBackground(Color.blue);
monthlyPayment.setForeground(Color.yellow);
monthlyPayment.setFont(new Font("Times New Roman", Font.PLAIN, 18));

chosenPT.setBackground(Color.blue);
chosenPT.setForeground(Color.yellow);
chosenPT.setFont(new Font("Times New Roman", Font.PLAIN, 18));

mortgageTable.setBackground(Color.black);
mortgageTable.setForeground(Color.red);
mortgageTable.setFont(new Font("Times New Roman", Font.PLAIN, 14));

monthlyPayment.setEditable(false);

setContentPane(pane);
setVisible(true);

}

public void actionPerformed(ActionEvent e)
{
String mi = e.getActionCommand();
System.out.println(mi);

Object command = e.getSource();

int loanTerm = 0;

{
loanTerm = 0;
}

{
loanTerm = 1;
}

{
loanTerm = 2;
}

double mortgage = 0;
double rate = 0;
double salary =0;
double [][] loans = {{7, 5.15}, {15, 5.875}, {30, 6.25},};

try
{

mortgage = Double.parseDouble(mortgageAmount.getText());

}
catch (NumberFormatException nfe)
{
JOptionPane.showMessageDialog (this, "Error! Invalid input!");
return;
}

double interestRate = loans [loanTerm][1];
double intRate = (interestRate / 100) / 12;
double loanTermMonths = loans [loanTerm] [0];
int months = (int)loanTermMonths * 12;
double interestRateMonthly = (intRate / 12);
double payment = mortgage * intRate / (1 - (Math.pow(1/(1 + intRate), months)));
double remainingLoanBalance = mortgage;
double monthlyPaymentInterest = 0;
double monthlyPaymentPrincipal = 0;
double salaryPercentage = 0;

NumberFormat myCurrencyFormatter = NumberFormat.getCurrencyInstance(Locale.US);

monthlyPayment.setText(myCurrencyFormatter.format(payment));
mortgageTable.setText("Month\tPrincipal\tInterest\tEnding Balance\n" +
"---------\t----------\t------------\t---------------------\n");

for (;months > 0 ; months -- )
{
monthlyPaymentInterest = (remainingLoanBalance * intRate);
//Calculate H = R x I
monthlyPaymentPrincipal = (payment - monthlyPaymentInterest);
//Calculate C = P - H
remainingLoanBalance = (remainingLoanBalance - monthlyPaymentPrincipal);
// Calculate R = R - C
salaryPercentage =(salary * 0.28);

// H = monthlyPaymentInterest
// R = remainingLoanBalance
// P = payment
// C = monthlyPaymentPrincipal
// I = interestRateMonthly

mortgageTable.setCaret (new DefaultCaret());
mortgageTable.append(String.valueOf(months) + "\t" +
myCurrencyFormatter.format(monthlyPaymentPrincipal) + "\t" +
myCurrencyFormatter.format(monthlyPaymentInterest) + "\t" +
myCurrencyFormatter.format(remainingLoanBalance) + "\n");
}
if(command == newcalcButton)
{
mortgageAmount.setText(null);
monthlyPayment.setText(null);
mortgageTable.setText(null);

}
}
public static void main(String[] args)
{
MikeFinalMorCalc JLabel= new MikeFinalMorCalc();
}

public void fRecordCount() {

try {

String temp;
numRec = 0;
numRec ++;
}

numRec = numRec /2;

}
catch (IOException e) {

System.out.println("There was an input/output error.");
System.exit(0);

}

}

try {
for(int xx = 0; xx < numRec;xx ++) {
}

}
catch (IOException e) {
System.out.println("There was an input/output error.");
System.exit(0);
}

}

}
[CODE]

Is This A Good Question/Topic? 0

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }