First off thank you in advance for any and all help that you can give me.. What I'm trying to do is to use an array for a mortgage calculator that displays the months payment for 3 different loans without it scrolling off the screen. When I compile it I get the following error
"(C:\Documents and Settings\new one\Desktop\POS407\MacApplet46.java:18: '(' expected
{
^
C:\Documents and Settings\new one\Desktop\POS407\MacApplet46.java:118: '}' expected
^
2 errors
Tool completed with exit code 1"
for the life of me I can't figure out where I went wrong. I believe it should work the way I have it set up or am I completely wrong?
[applet code]
CODE
<HTML>
<APPLET CODE = "MacApplet46" Width = 410 Height = 410>
</APPLET>
</HTML>
[Main App code]
CODE
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.Math;
import java.text.DecimalFormat;
public class MacApplet46 extends Applet implements ActionListener
{
public void calculateFormulas
{
//declare variables
int payment_frequency = 12; // The use of this variable allows us to change the frequency only in one place.
int number_of_payments[]={7*payment_frequency,15*payment_frequency,30*payment_frequency}; // or the following
// int number_of_payments[]={84,180,360};
double [] interest_rate = {5.35/100,5.5/100,5.75/100}; // Need to divide by 100
double [] principal = {100000.00,200000.00,300000.00};
double [] pp = new double[3];
pp[0]=1.4;
double monthly_interest;
double [] monthly_payment =new double[3];
DecimalFormat myVar =new DecimalFormat("####0.00");
//construct components
Label companyLabel = new Label("Welcome to Macs Mortgage Calculator");
Label loanAmountLabel = new Label("Please enter your loan amount");
TextField loanAmountField = new TextField(10);
Label loanTermLabel = new Label("Please enter loan term length");
TextField loanTermField = new TextField(10);
Label interestLabel = new Label(" Please enter your interest rate");
TextField interestField = new TextField(10);
Button calcButton = new Button("Calculate");
Label loanAmounterrorLabel = new Label(" ");
TextField loanAmounterrorField = new TextField(0);
Label loanInteresterrorLabel = new Label(" ");
TextField loanInteresterrorField = new TextField(0);
Label loanTermerrorLabel = new Label(" ");
TextField loanTermerrorField = new TextField(0);
Label loanPaymentsLabel = new Label (" ");
TextField loanPaymentsField = new TextField(0);
Label outputLabel = new Label(
"Click Calculate to find out how much your payments will be");
public void init()
{
setBackground(Color.green);
setForeground(Color.black);
add(companyLabel);
add(loanAmountLabel);
add(loanAmountField);
add(loanTermLabel);
add(loanTermField);
add(interestLabel);
add(interestField);
add(calcButton);
add(loanPaymentsField);
add(loanPaymentsLabel);
add(loanAmounterrorLabel);
loanAmounterrorLabel.setForeground(Color.red);
add(loanTermerrorLabel);
add(loanInteresterrorLabel);
calcButton.addActionListener(this);
add(outputLabel);
}
public void actionPerformed(ActionEvent e)
{
loanAmount = Integer.parseInt(loanAmountField.getText());
for(x=0; x <interest_rate.length; x++)
{
output = AmountFormat.format(principal[x]);
loanAmountLabel.set.Text("Principal \t: " + output);
monthly_interest = interest_rate[x] / payment_frequency;
temp= Math.pow(1 + monthly_interest,(-1* number_of_payments[x]));
monthly_payment[x] = principal[x] * monthly_interest / (1 - (temp));
// Could have used a singular variable like payment, for monthly payment instead of an array
output = NumberFormat.format(interest_rate[x]*100);
loanInterestLabel.set.Text("Interest Rate \t: " + output + " %");
loanPaymentsLabel.set.Text("# of payments \t: " + number_of_payments[x]);
output = AmountFormat.format(monthly_payment[x]);
// instead of monthly+payment[x], could have used payment as indicated above.
outputLabel.setText("Monthly payment : " + output + "\n");
}}
[end of code]
*1lacca: added code tags
This post has been edited by 1lacca: 17 Sep, 2007 - 09:30 AM