Need Help with this java applet
Having issues with this java applet the error code I'm getting when trying to compile is cannot fine symbol M= MonthlyPayment = CalculateMonthlyPayment();is the only error I get / any help would be greatly appreciated.
Code :
import javax.swing.*;
import java.awt.*;
import java.text.*;
import java.awt.event.*;
public class SchoolApplet9 extends JApplet implements ActionListener {
double userAmount;
double userInterest;
double userTerm;
int month = 0;
double remainBalance = 0;
double interestPayment = 0;
double principalPaid = 0;
JPanel row1;
JLabel lblAmount;
JTextField txtAmount;
JLabel lblInterest;
JTextField txtInterest;
JLabel lblTerm;
JTextField txtTerm;
JLabel lblMonthlyPayments;
JTextField txtMonthlyPayments;
JLabel lblPayment;
JTextField txtPayment;
JPanel row2;
JLabel lblHeader;
JTextArea txtResults;
JScrollPane textPane;
JPanel row3;
JButton calculateButton;
JButton clearButton;
JButton exitButton;
public void init()
{
//Instantiate GUI Components
// row1
row1 = new JPanel();
lblAmount = new JLabel(" Loan Amount: $", JLabel.LEFT);
txtAmount = new JTextField(10);
lblMonthlyPayments = new JLabel("Monthly Payments", JLabel.LEFT);
txtMonthlyPayments = new JTextField(6);
lblInterest = new JLabel("Interest Per Period %", JLabel.LEFT);
txtInterest = new JTextField(6);
lblTerm = new JLabel("Term in Years", JLabel.LEFT);
txtTerm = new JTextField(6);
// TO DO
// create a new JLabel and assign it to lblPayment
// create a new JTextField(10) and assign it to txtPayment
// row2
row2 = new JPanel(new BorderLayout());
String pad = " ";
lblHeader = new JLabel("Payment #"+pad+"Monthly Payment Amount:"+pad+"Interest Paid:"+pad+"Principal"+pad+"Balance:");
txtResults = new JTextArea(10, 53);
textPane = new JScrollPane(txtResults);
//row 3
row3 = new JPanel(new GridLayout(1,3,75,1));
calculateButton = new JButton("Calculate");
clearButton = new JButton("Clear");
exitButton = new JButton("Exit");
//Build GUI
setSize(600, 250);
row1.add(lblAmount);
row1.add(txtAmount);
row1.add(lblMonthlyPayments);
row1.add(txtMonthlyPayments);
row1.add(lblInterest);
row1.add(txtInterest);
row1.add(lblTerm);
row1.add(txtTerm);
// To DO
// add lblPayment & txtPayment to row1
// set editable of txtPayment to false: txtPayment.setEditable(false);
//
textPane.setPreferredSize(new Dimension(610,200));
row2.add(lblHeader,BorderLayout.NORTH);
row2.add(textPane,BorderLayout.CENTER);
//Create Calculate button and add listener
calculateButton.addActionListener(this);
clearButton.addActionListener(this);
exitButton.addActionListener(this);
row3.add(exitButton);
row3.add(clearButton);
row3.add(calculateButton);
getContentPane().add(row1,BorderLayout.NORTH);
getContentPane().add(row2,BorderLayout.CENTER);
getContentPane().add(row3,BorderLayout.SOUTH);
}
//Define actions performed for buttons
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == calculateButton)
{
double balance = 0;
double monthPayment=0;
userAmount = Double.parseDouble(txtAmount.getText());
userInterest = Double.parseDouble(txtInterest.getText());
userTerm = Double.parseDouble(txtTerm.getText());
//formats answer in currency format then to string format for display
NumberFormat fmt = NumberFormat.getCurrencyInstance();
[U]MonthlyPayment = CalculateMonthlyPayment();[/U]
String payment = fmt.format(monthPayment);
// TO DO
// Display payment in txtPayment : txtPayment.setText(" "+ payment);
//
balance = userAmount;
month = (int)userTerm * 12;
for(int index = 1; index <= month ; index++)
{
interestPayment = balance * (userInterest * .01/12);
principalPaid = monthPayment - interestPayment;
remainBalance = balance - principalPaid;
txtResults.append(" " + index + "\t\t "+ fmt.format(balance) + "\t\t"
+ fmt.format(interestPayment) + "\t\t" + fmt.format(remainBalance) + "\n");
balance = remainBalance;
}
}
else if (e.getSource() == clearButton)
{
txtAmount.setText(null);
txtPayment.setText(null);
txtResults.setText(null);
}
else if (e.getSource() == exitButton)
{
System.exit(0);
}
}
//Mortgage Payment Calculations
public void CalculateMonthlyPayment()
{
double dAmount=16000.00; //initial amount of $16,000.00
double dPercentRate=0.124; //12.4% APR
//following the lesson variables...
int j=0; //payment number
double p=dAmount;
double dPrevBal=dAmount;
double i=(dPercentRate/12); //interest per pay period
double t=(i*p); //interest paid and will update
double n=36; // 3 years
double r=0.00; //monthly payment
double a = r-t; //will change
double b=(dPrevBal-a); //will change
//first...initial data
for(j=1;j<=n;j++)
{
r=((p * dPercentRate / 12)) / (1.0 - Math.pow(((dPercentRate / 12) + 1.0), (-(n)))); //ugh!! ...
t=(i*dPrevBal);
a = r-t;
b=(dPrevBal-a);
dPrevBal=b;
System.out.println("Payment number: "+j+"\nPayment amount: "+r+"\nInterest Amount: "+t+"\nMontly payment-Interest: "+a+"\nNew Balance: "+b+"\n");
}
System.exit(0);
}
}[/QUOTE]
Re: Need Help with this java applet
Please Edit your post and wrap your code with
[code=java]
<YOUR CODE HERE>
[/code]
to get highlighting and preserve formatting.
Please post the full text of the error message that shows the name of the symbol and where the error happens.
Re: Need Help with this java applet
okay thx I wrapped the code and put the U\ on each of the side where I'm getting the errors for clarification.
Re: Need Help with this java applet
Please post the full text of the error message that shows the name of the symbol and where the error happens.
The U\ is not found with a Find.
Re: Need Help with this java applet
So you know the line causing the error, now all you have to do is make sure that the identifiers on that line exist in your program. So on that note, where do you declare the MonthlyPayment variable?
Re: Need Help with this java applet
Quote:
MonthlyPayment = CalculateMonthlyPayment();
What data type is MonthlyPayment? I do not see it anywhere like curmudgeon said.
What data type does CalculateMonthlyPayment() return?