I am looking to create a mortgage applet with an array for the 3 amounts. There is something I am missing here. Any help can be of use
/* GOAL Display the mortgage payment amount. Then, list 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. */
import javax.swing.*;
import java.awt.event.*;
import javax.swing.border.*;
import java.awt.*;
import java.lang.*;
import java.text.*;
import java.util.*;
public class Mortgage extends javax.swing.JApplet implements ActionListener {
double[] annualInterests = {5.35,5.5,5.75};
int[] numOfYears = {7,15,30};
double monthlyPayment, monthlyInterest, denominator, numOfMonths, getMortgageAmount;
double principal;
double interest;
int term, i;
float paymentdue;
JLabel title = new JLabel(" Mortgage Calculator ");
JLabel title = new JLabel(" Please enter Principal amount and select term with rate ");
JTextField appPrincipal=new JTextField(10);
JTextField appTerm=new JTextField(2);
JTextField appInterest=new JTextField(5);
JTextField appMonthlyPayment=new JTextField(10);
JLabel ErrorMsg=new JLabel("");
Font bigFont = new Font("Helvetica", Font.ITALIC, 24);
public void init()
{
Container con = getContentPane();
con.setLayout(new BorderLayout());
JPanel TopLabel=new JPanel();
TopLabel.setLayout(new FlowLayout());
title.setFont(bigFont);
con.add("North",title);
setBackground(Color.blue);
setForeground(Color.yellow);
JPanel MainForm=new JPanel();
MainForm.setLayout(new GridLayout(0,3));
JLabel label1=new JLabel(" Term ",SwingConstants.RIGHT);
MainForm.add(label1);
JButton bttn = new JButton(" 7 Years at 5.35% ");
bttn.addActionListener( new ActionListener() { }
public void actionPerformed(ActionEvent evt) {
// This method will respond to the user's click entry for the mortgage term & interest
i = 0;
MainForm.add(i);
}
JButton bttn = new JButton(" 15 Years at 5.5% ");
bttn.addActionListener( new ActionListener() {
}
public void actionPerformed(ActionEvent evt) {
i = 1;
MainForm.add(i);
}
JButton bttn = new JButton(" 30 Years at 5.75% ");
bttn.addActionListener( new ActionListener() {
}
public void actionPerformed(ActionEvent evt) {
i = 2;
MainForm.add(i);
}
JLabel label2=new JLabel(" Principle ",SwingConstants.RIGHT);
MainForm.add(label2);
MainForm.add(appPrincipal);
JLabel label3=new JLabel(" Interest Rate ",SwingConstants.RIGHT);
MainForm.add(label3);
MainForm.add(appInterest);
JLabel label4=new JLabel("Result ",SwingConstants.RIGHT);
MainForm.add(label4);
MainForm.add(appMonthlyPayment);
con.add("West",MainForm);
JPanel ButtonPanel=new JPanel();
ButtonPanel.setLayout(new BorderLayout());
ButtonPanel.add("North",ErrorMsg);
JButton Calculate=new JButton("Calculate");
Calculate.addActionListener(this);
ButtonPanel.add("Center",Calculate);
con.add("South",ButtonPanel);
appMonthlyPayment.setEditable(false);
}
public void start()
{
repaint();
}
public void actionPerformed(ActionEvent divide)
{
DecimalFormat decimalPlaces=new DecimalFormat("0.00");
appMonthlyPayment.setText("");
term = Integer.parseInt(appTerm.getText());
interest = Double.parseDouble(appTerm.getText());
principal = Double.parseDouble(appPrincipal.getText());
monthlyInterest = annualInterests[i]/(12*100);
int totalNumOfMonths = numOfYears[i]*12;
int months= term*12;
monthlyInterest = interest/(12 * 100);
denominator = Math.pow(1 + monthlyInterest, -(term*12));
denominator = 1 - denominator;
monthlyPayment = principal * (monthlyInterest / denominator);
monthlyPayment = (double)(principal*(monthlyInterest / (1-(Math.pow((1+monthlyInterest),(numOfMonths*-1))))));
return monthlyPayment;
double getMonthlyPrincipal, monthlyPayment, remainingPrincipal;
return monthlyPayment - (remainingPrincipal * monthlyInterest);
appMonthlyPayment.setText("Payment = " + monthlyPayment);
}
}