I am new to Java so be nice.
I am having a problem compiling my program. To make a quick summary of what it is, I am creating a mortgage calculator (applet) that will calculate a monthly payment based on the user's input of the Principal, Loan Term, and Interest Rate.
I keep getting the error: "Missing Return Statement }" And it states that the line is located at the second to the last closing brackets. I don't understand what I am doing wrong. I have already double checked my closing brackets and that didn't seem to be the problem. But is there a line of code that I am missing?
Would anyone mind giving me some guidance so that I may be able to correct my mistake please? Any help is greatly appreciated. Thanks
import java.text.*;
import java.awt.*;
import java.applet.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import java.math.*;
import java.util.*;
import javax.swing.text.JTextComponent.*;
import javax.swing.JTextField.*;
import javax.swing.event.ChangeListener.*;
import java.awt.event.ActionListener.*;
import java.lang.Integer.*;
import java.lang.*;
import javax.swing.event.*;
import javax.swing.text.*;
public class test4 extends JApplet implements ActionListener
{
JLabel heading = new JLabel("McBride Financial Services \n" + "Mortgage Calculator \n");
Font newFontOne = new Font("TimesRoman", Font.BOLD, 20);
Font newFontTwo = new Font("TimesRoman", Font.ITALIC, 16);
JButton calculate = new JButton("Calculate");
JLabel instructions = new JLabel("Please fill in all areas below");
private double principalAmount;
private JLabel principalLabel = new JLabel("Principal Amount");
private NumberFormat principalFormat;
private JFormattedTextField enterPrincipal = new JFormattedTextField(principalFormat);
private int loanTermLength;
private JLabel loanTermLabel = new JLabel("Loan Term");
private NumberFormat loanTermFormat;
private JFormattedTextField enterLoanTerm = new JFormattedTextField(loanTermFormat);
private double loanInterestRate;
private JLabel interestRateLabel = new JLabel("Interest Rate");
private NumberFormat interestRateFormat;
private JFormattedTextField enterInterestRate = new JFormattedTextField(interestRateFormat);
private double finalPayment;
private JLabel finalPaymentLabel = new JLabel("Monthly Payment is: $ ");
private NumberFormat finalPaymentFormat;
private JFormattedTextField displayFinalPayment = new JFormattedTextField(finalPaymentFormat);
public void init()
{
Container con = getContentPane();
heading.setFont(newFontOne);
instructions.setFont(newFontTwo);
con.add(heading);
con.add(instructions);
con.add(enterPrincipal);
con.add(enterLoanTerm);
con.add(enterInterestRate);
con.add(calculate);
calculate.addActionListener(this);
enterPrincipal.requestFocus();
}
public void repaint()
{
repaint();
}
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
if (source == enterPrincipal)
{
principalAmount = ((Number)enterPrincipal.getValue()).doubleValue();
}
else if (source == enterLoanTerm)
{
loanTermLength = ((Number)enterLoanTerm.getValue()).intValue();
}
else if (source == enterInterestRate)
{
loanInterestRate = ((Number)enterInterestRate.getValue()).doubleValue();
}
}
private void formatting()
{
principalFormat = NumberFormat.getNumberInstance();
loanTermFormat = NumberFormat.getInstance();
interestRateFormat = NumberFormat.getPercentInstance();
finalPaymentFormat = NumberFormat.getCurrencyInstance();
}
public double calculatePayment(double payment, double totalPrincipal, double intRate, double term, int totalPayments, double periodInterest)
{
periodInterest = intRate / 12;
totalPayments = loanTermLength * 12;
totalPrincipal = ((Number)enterPrincipal.getValue()).doubleValue();
intRate = ((Number)enterInterestRate.getValue()).doubleValue();
term = ((Number)enterLoanTerm.getValue()).intValue();
loanInterestRate = intRate / 100;
if(totalPrincipal >= 0.01)
{
return payment = totalPrincipal * (periodInterest * Math.pow((1 + periodInterest), totalPayments)) / ((Math.pow((1 + periodInterest), totalPayments) - 1));
}
}
}