I am hoping to get some help with a mortgage calculator assignment I am doing in Netbeans. Here is what I need to do: Write the program in Java (with a graphical user interface) and have it calculate and display the mortgage payment amount from user input of the amount of the mortgage and the user's selection from a menu of available mortgage loans:
- 7 years at 5.35%
- 15 years at 5.5%
- 30 years at 5.75%
Use an array for the mortgage data for the different loans. Display the mortgage payment amount followed by the loan balance and interest paid for each payment over the term of the loan. Allow the user to loop back and enter a new amount and make a new selection or quit. Insert comments in the program to document the program.
The issue I am having is that I am not getting the correct results. No matter what I put in I only get the interest rate and years in the results text box instead of monthly payment and interest. I cant figure out what im doing wrong.
package CR5; import java.text.DecimalFormat; import java.text.NumberFormat; public class ChangeRequest5 extends javax.swing.JFrame { public int[] years = new int[]{7, 15, 30}; public double[] interestRates = new double[]{5.35, 5.5, 5.75}; DecimalFormat decimalPlaces = new DecimalFormat("0.00"); public ChangeRequest5() { initComponents(); } private void exitButtonActionPerformed(java.awt.event.ActionEvent evt) { System.exit(0);//exits program } private void clearButtonActionPerformed(java.awt.event.ActionEvent evt) { loanAmountField.setText(null);//clears loan amount resultsTextField.setText(null);//clears results field loanComboBox.setSelectedIndex(0);//resets combo box } private void calculateButtonActionPerformed(java.awt.event.ActionEvent evt) { //creates array for interest rate double[] interestRate = new double[3]; interestRate[0] = 5.35; interestRate[1] = 5.5; interestRate[2] = 5.75; //creates array for the number of years int[] numberOfYears = new int[3]; numberOfYears[0] = 7; numberOfYears[1] = 15; numberOfYears[2] = 30; { int X = loanComboBox.getSelectedIndex(); while (X < 3) { //declare variables double loanAmount = 200000; //Principle double rate = 0.0; //monthly interest rate double noOfMonths = 0.0; // Number of months for the loan double monthlyPayment = 0.0; //Monthly Payment //converts dollar amounts to a decimal format DecimalFormat cash = new DecimalFormat("$0.00"); //calculate monthly interest rate rate = interestRate[X] / (12 * 100); //calculate total number of months for loan noOfMonths = numberOfYears[X] * 12; //Calculate Monthly Payment noOfMonths = (loanAmount * (rate * (Math.pow((1 + rate), monthlyPayment)) / (Math.pow((1 + rate), monthlyPayment) - 1))); //begins the loop process for 360 payments for (int i = 1; i <= noOfMonths; i++) { //begins the loop process for 360 payments //displays results this.resultsTextField.setText(+interestRate[X] + "% for " + numberOfYears[X] + " years is " + cash.format(monthlyPayment)); X = X + 1; resultsTextField.setText("Number of payments=" + numberOfYears + "Monthly Payment= " + cash.format(monthlyPayment) + "Interest Payment= " + cash.format(interestRates) + "Mortgage Balance= " + cash.format(loanAmount)); } } private void loanComboBoxActionPerformed(java.awt.event.ActionEvent evt) { } private void resultsTextFieldActionPerformed(java.awt.event.ActionEvent evt) { } private javax.swing.JButton calculateButton; private javax.swing.JButton clearButton; private javax.swing.JButton exitButton; private javax.swing.JComboBox jComboBox1; private javax.swing.JScrollBar jScrollBar1; private javax.swing.JTextField loanAmountField; private javax.swing.JComboBox loanComboBox; private javax.swing.JLabel loanLabel; private javax.swing.JTextField resultsTextField; // End of variables declaration }