I have been trying to work on this calculator for a while and I need help. I'm getting "12" errors. I'm very new at this and I really need the help of someone that can please take the time to explain what I'm doing wrong. I would really appreciated.
/*
* Program: Mortgage Calculator with Graphical User Interface
* Programs accepts user input in 3 text fields: Mortgage Amount, Mortgage Term, and Interest Rate.
* User can calculate the monthly payment amount from a selection of the following:
* 7 year loan at 5.35%
* 15 year loan at 5.50%
* 30 year loan at 5.75%
* The user can enter the new available choices and get the different loan amounts, the the balance and the monthly interest in an array.
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.Double;
import java.text.DecimalFormat;
import javax.swing.event.*;
import java.text.*;
import java.util.*;
import javax.swing.border.*;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JApplet;
// Create MortgageCalculator class
public class MortgageCalc3 extends javax.swing.JApplet implements ActionListener {
// Radio Button Selection
JPanel rowOne = new JPanel();
JRadioButton rbOne = new JRadioButton("7 Years/5.35%", true);
JRadioButton rbTwo = new JRadioButton("15 Years/5.5%", true);
JRadioButton rbThree = new JRadioButton("30 Years/5.75%", true);
// Text Amount for Mortgage
JPanel rowTwo = new JPanel();
JLabel mortgageLabel = new JLabel("Mortgage Amount $", JLabel.LEFT);
JTextField mortgageText = new JTextField(10);
JLabel termLabel = new JLabel("Mortgage Term (Years)", JLabel.LEFT);
JTextField termText = new JTextField(3);
JLabel intRateLabel = new JLabel("Interest Rate (%)", JLabel.LEFT);
JTextField intRateText = new JTextField(5);
JLabel mPaymentLabel = new JLabel("Monthly Payment $", JLabel.LEFT);
JTextField mPaymentText = new JTextField(10);
// Create buttons to calculate payment, amortizaton, and clear fields
JPanel rowThree = new JPanel();
JButton calculateButton = new JButton("CALCULATE");
JButton clearButton = new JButton("CLEAR");
JButton exitButton = new JButton("EXIT");
// Create Label for Text Box
JPanel rowFour = new JPanel();
JLabel paymentLabel = new JLabel("Payment #");
JLabel balLabel = new JLabel(" Balance");
JLabel ytdPrincLabel = new JLabel(" Principal");
JLabel ytdIntLabel = new JLabel(" Interest");
// Display area
JPanel rowFive = new JPanel(new FlowLayout());
JTextArea textArea = new JTextArea(10, 31);
JScrollPane scroll = new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
public MortgageCalc3() {
super("KARIN'S CALC");
setSize(400, 485);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container pane = getContentPane();
JScrollPane scroll1 = new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
FlowLayout layout = new FlowLayout(FlowLayout.LEFT);
pane.setLayout(layout);
// Add to the screen
FlowLayout layout1 = new FlowLayout();
rowOne.setLayout(layout1);
// Add Radio Button Group
ButtonGroup btnGrp = new ButtonGroup();
btnGrp.add(rbOne);
btnGrp.add(rbTwo);
btnGrp.add(rbThree);
rowOne.add(rbOne);
rowOne.add(rbTwo);
rowOne.add(rbThree);
pane.add(rowOne);
// Create a border around the radio buttons
Border titledRadioBorder =
BorderFactory.createTitledBorder("Make your selections");
rowOne.setBorder(titledRadioBorder);
// Listeners
rbOne.addActionListener(this);
rbTwo.addActionListener(this);
rbThree.addActionListener(this);
// Add Labels & Text Boxes
GridLayout layout2 = new GridLayout(4, 1);
rowTwo.setLayout(layout2);
rowTwo.add(mortgageLabel);
rowTwo.add(mortgageText);
mortgageText.setText("200000");
rowTwo.add(termLabel);
rowTwo.add(termText);
termText.setText("30");
rowTwo.add(intRateLabel);
rowTwo.add(intRateText);
intRateText.setText("5.75");
rowTwo.add(mPaymentLabel);
rowTwo.add(mPaymentText);
mPaymentText.setEnabled(false);
pane.add(rowTwo);
// Add Buttons
FlowLayout layout3 = new FlowLayout(FlowLayout.CENTER, 10, 10);
rowThree.setLayout(layout3);
rowThree.add(calculateButton);
calculateButton.setBackground(Color.green);
rowThree.add(clearButton);
clearButton.setBackground(Color.white);
rowThree.add(exitButton);
exitButton.setBackground(Color.red);
pane.add(rowThree);
// Listeners
calculateButton.addActionListener(this);
clearButton.addActionListener(this);
exitButton.addActionListener(this);
// Add Text Box Label
FlowLayout layout4 = new FlowLayout(FlowLayout.LEFT, 10, 10);
rowFour.setLayout(layout4);
rowFour.add(paymentLabel);
rowFour.add(balLabel);
rowFour.add(ytdPrincLabel);
rowFour.add(ytdIntLabel);
pane.add(rowFour);
// Add Text Box
FlowLayout layout5 = new FlowLayout(FlowLayout.CENTER, 10, 10);
rowFive.setLayout(layout5);
rowFive.add(scroll1);
pane.add(rowFive);
setContentPane(pane);
setVisible(true);
}
public static void main(String[] args) throws Exception {
DecimalFormat dollarAmount = new DecimalFormat("#,###.00");
DecimalFormat percentAmount = new DecimalFormat("##.##");
MortgageCalc3 frame = new MortgageCalc3();
}
public void setResultValue() {
double monthlyPayment, monthlyInterest, denominator, numOfMonths, getMortgageAmount,MortgageInfo ;
double[] annualInterests = {5.35,5.5,5.75}; //Interest Array
int[] numOfYears = {7,15,30}; //Term Array
double principal = Double.parseDouble(mortgageText.getText());
double term = Double.parseDouble(termText.getText());
double interest = Double.parseDouble(intRateText.getText());
float paymentdue;
monthlyInterest = annualInterests[]/(12*100);
int totalNumOfMonths = numOfYears[]*12;
int months= (int) (term * 12);
monthlyInterest = interest/(12 * 100);
denominator = Math.pow(1 + monthlyInterest, -(term*12));
denominator = 1 - denominator;
monthlyPayment = principal * (monthlyInterest / denominator);
// Monthly payment formula: M = P x (J/(1-(1+J)^-N));
// M = P * ( J / (1 - (1 + J) ** -N));
// source: http://www.hughchou.org/calc/formula.html
monthlyPayment = (double)(principal*(monthlyInterest / (1-(Math.pow((1+monthlyInterest),(numOfMonths*-1))))));
return monthlyPayment - (remainingPrincipal * monthlyInterest);
//calculate the monthly interst using simple interest.
double getremainingPrincipal;
return monthlyPayment - (remainingPrincipal * monthlyInterest);
// Finally, set the text field to show the result
mPaymentText.setText("Payment = " + monthlyPayment);
}
public void actionPerformed(ActionEvent event)
{
try
{ // Capture the Info the User Entered, remove 's and make it a double
MortgageInfo.setInterestRatePercent(Double.parseDouble(intRateText.getText().replaceAll(",","")));
MortgageInfo.setloanAmount(Double.parseDouble(mortgageText.getText().replaceAll(",","")));
MortgageInfo.setloanYears(Double.parseDouble(termText.getText().replaceAll(",",""))); // Get & Format the Results
double test=MortgageInfo.getpaymentAmount();
DecimalFormat myFormatter = new DecimalFormat("$###,###.00");
mPaymentText.setText("<html><font color=blue>"+myFormatter.format(test)+"</font></html>");
}
catch(Exception except)
{
}
}
{
rbTwo.addActionListener(new java.awt.event.ActionListener() {
public void ActionListeneractionPerformed(ActionEvent event) {
rbTwoActionPerformed(event);
}
public void actionPerformed(ActionEvent event) {
throw new UnsupportedOperationException("Not supported yet.");
}
});
rbThree.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent event) {
rbThreeActionPerformed(event);
}
});
rbOne.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent event) {
rbOneActionPerformed(event);
}
});
}
private void rbTwoActionPerformed(java.awt.event.ActionEvent event) {
termText.setText("15");
intRateText.setText("5.5");
}
private void rbThreeActionPerformed(java.awt.event.ActionEvent event) {
termText.setText("30");
intRateText.setText("5.75");
}
private void rbOneActionPerformed(java.awt.event.ActionEvent event) {
termText.setText("7");
intRateText.setText("5.35");
}
//***************Create commands for JMenuBar**************************
public void actionPerformed(ActionEvent event) {
Object command1 = event.getSource();
if (event.getSource() == calculateButton) {
setResultValue();
}
//*************Exit Routine for File Exit******************************
if (event.getSource() == exitButton) {
System.exit(0);
}
//*************Clear Routine for Function Clear************************
if (event.getSource() == clearButton) {
{
mortgageText.setText(null);
termText.setText(null);
intRateText.setText(null);
mPaymentText.setText(null);
}
}
}
}