Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Need Help with this java applet

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

    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]
    Last edited by bruizer; September 23rd, 2012 at 08:09 PM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default 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.

    cannot fine symbo
    Please post the full text of the error message that shows the name of the symbol and where the error happens.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Sep 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default 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.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default 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?

  6. #6
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Need Help with this java applet

    MonthlyPayment = CalculateMonthlyPayment();
    What data type is MonthlyPayment? I do not see it anywhere like curmudgeon said.
    What data type does CalculateMonthlyPayment() return?

Similar Threads

  1. Running a java applet inside a java window?
    By frozen java in forum Java Theory & Questions
    Replies: 3
    Last Post: July 3rd, 2012, 10:55 PM
  2. [SOLVED] Java applet
    By ikocijan in forum What's Wrong With My Code?
    Replies: 11
    Last Post: July 3rd, 2012, 02:54 AM
  3. Replies: 29
    Last Post: May 18th, 2012, 02:16 PM
  4. Need help with Java applet
    By Trendle in forum Java Applets
    Replies: 0
    Last Post: May 18th, 2012, 11:30 AM
  5. My first java applet
    By Fathermucker in forum Java Applets
    Replies: 2
    Last Post: April 4th, 2012, 01:26 PM