Reached end of file while parsing (Error)

  • (2 Pages)
  • +
  • 1
  • 2

27 Replies - 5229 Views - Last Post: 02 August 2009 - 06:20 PM Rate Topic: -----

#1 Floridaboy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 02-August 09

Reached end of file while parsing (Error)

Post icon  Posted 02 August 2009 - 03:31 PM

hello new to the java world but I am in a little need of help have one error and can not seem to locate where it is. It's saying that it is the last line but nothing wrong there. Any advice.
import java.awt.*;
import java.text.NumberFormat;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Graphics;
import java.awt.geom.Rectangle2D;


public class Mortgage_wk5 extends JFrame implements ActionListener
{

	// Declare Labels
	JLabel AmountLabel = new JLabel( "Principal Amount:$ " );
	JLabel PaymentLabel = new JLabel( "Monthly Payment: " );
	JLabel InterestLabel = new JLabel( "Interest Rate %: " );
	JLabel TermLabel = new JLabel( "Length of Loan of Loan in Years: " );

	// Declare Text Fields
	JTextField mortgageAmount = new JTextField(7);
	JTextField Payment = new JTextField(7);
	JTextField InterestRate = new JTextField(3);
	JTextField Term = new JTextField(3);


	// Declare Buttons
	JButton Loan7 = new JButton( "7 years at 5.35%" );
	JButton Loan15 = new JButton( "15 years at 5.50%" );
	JButton Loan30 = new JButton( "30 years at 5.75%" );
	JButton ExitButton = new JButton( "Exit" );
	JButton ClearButton = new JButton( "Clear All" );
	JButton CalculateButton = new JButton( "Calculate Loan" );


	// Declares Text Area and ScrollPane
	JTextArea LoanPayments = new JTextArea(20,50);
	JTextArea GraphArea = new JTextArea(19,50);
	JScrollPane scroll = new JScrollPane(LoanPayments);


	public Mortgage_wk5()
	{
		//Frame, Panel, and Layout set up
		super("mortgage_wk5");
		setSize(900, 800);
		setLocation(200, 0);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		JPanel pane = new JPanel(new GridLayout(3,1));

		//Setup container and contents
		Container grid = getContentPane();
		grid.setLayout(new GridLayout(4,0,4,4));

		pane.add(grid);
		pane.add(scroll);
		grid.add(AmountLabel);
		grid.add(mortgageAmount);
		grid.add(InterestLabel);
		grid.add(InterestRate);
		grid.add(TermLabel);
		grid.add(Term);
		grid.add(PaymentLabel);
		grid.add(Payment);
		grid.add(Loan7);
		grid.add(Loan15);
		grid.add(Loan30);
		grid.add(CalculateButton);
		grid.add(ClearButton);
		grid.add(ExitButton);
		Payment.setEditable(false);
		setContentPane(pane);
		setContentPane(pane);
		setVisible(true);

		//Adds Action Listeners
		ExitButton.addActionListener(this);
		ClearButton.addActionListener(this);
		Loan7.addActionListener(this);
		Loan15.addActionListener(this);
		Loan30.addActionListener(this);
		mortgageAmount.addActionListener(this);
		InterestRate.addActionListener(this);
		Term.addActionListener(this);
		Payment.addActionListener(this);
		CalculateButton.addActionListener(this);


	}

	public void actionPerformed(ActionEvent e) {
		Object command = e.getSource();
		if (command == ExitButton) {
			System.exit(0);	 }
		else if (command == Loan7) {
			calcLoan(7, 5.35);	 }
		else if (command == Loan15) {
			calcLoan(15, 5.50);	 }
		else if (command == Loan30) {
			calcLoan(30, 5.75);	 }
		else if (command == CalculateButton ) {
			double terms = 0;
			double rates = 0;
			try {
				terms = Double.parseDouble(Term.getText());
				rates = Double.parseDouble(InterestRate.getText());
			} catch (Exception ex) {
				LoanPayments.setText("Invalid term or rate Amount");
				return;

			}

			calcLoan(terms, rates);	 }
		else if (command == ClearButton) {
			mortgageAmount.setText("");
			Payment.setText("");
			InterestRate.setText("");
			Term.setText("");
			LoanPayments.setText("");

		}

	}

	private void calcLoan(double terms, double rates) {
		Term.setText(String.valueOf(terms) );
		InterestRate.setText(String.valueOf(rates));
		double amount = 0;
		try {
			amount = Double.parseDouble(mortgageAmount.getText());
			//Parse text to
		}	 catch (Exception ex) {		  LoanPayments.setText
			("Invalid mortgage Amount");
		return;	 }
		double interestRate = rates;

		// Sets interestRate amount
		double intRate = (interestRate / 100) / 12;

		// Calculates Interest Rate
		// double loanTermMonths = terms;
		// Calculates Loan Term in Months
		int months = (int)terms * 12;

		// Converts Loan Term to Months
		double rate = (intRate / 12);

		// Converts Annual interest rate to monthly interest rate
		double payment = amount * intRate / (1 - (Math.pow(1/(1 + intRate), months)));

		// Calculation for Monthly payment
		double remainingPrincipal = amount;

		// Sets Remaining Balance
		double MonthlyInterest = 0;


		// saves interest payment
		double MonthlyAmt = 0;

		// saves principal payment
		//double x[] = new double[1]; x[0] = 0;
		// Number formatter to format output in table
		NumberFormat CurrencyFormatter = NumberFormat.getCurrencyInstance();
		Payment.setText(CurrencyFormatter.format(payment));
		LoanPayments.setText("Month\tPrincipal\tInterest\tEnding Balance\n");

		// double[] values = new double[months];
		// counting the month backward is confusing
		// for(;months > 0; months -- ) 
		int currentMonth = 0;	 while(currentMonth < months) {

			//Append loop for mortgage detail in the text area
			MonthlyInterest = (remainingPrincipal * intRate);

			//Monthly Payment Toward Interest
			MonthlyAmt = (payment - MonthlyInterest);

			//Monthly Payment Toward Principal
			remainingPrincipal = (remainingPrincipal - MonthlyAmt);

			//Remaining loan Balance
			// values[months-1] = remainingPrincipal;
			LoanPayments.append((++currentMonth) + "\t" +
					CurrencyFormatter.format(MonthlyAmt) + "\t" +
					CurrencyFormatter.format(MonthlyInterest) + "\t" +
					CurrencyFormatter.format(remainingPrincipal) + "\n");

			GraphArea.append("" + remainingPrincipal);
		}
	}

	public class GraphProgram extends JPanel

	{
		GraphCanvas graph = new GraphCanvas();

		public GraphProgram()
		{
			setLayout(new BorderLayout());
			setSize(300, 300);

			add(graph, BorderLayout.CENTER);
		}

		public  void setValues(double[] values) {
			graph.setValues(values);
		}
		public class CoordCanvas extends Canvas
		{
			protected float viewLeft;
			protected float viewRight;
			protected float viewTop;
			protected float viewBottom;

			public void setXRange(float left, float right)
			{
				viewLeft = left;
				viewRight = right;
			}

			public void setYRange(float top, float bottom)
			{
				viewTop = top;
				viewBottom = bottom;
			}

			public float toX(float x)
			{
				return (x - viewLeft) * getSize().width / (viewRight - viewLeft);
			}

			public float toY(float y)
			{
				return (y - viewTop) * getSize().height / (viewBottom - viewTop);
			}

			public float toWidth(float w)
			{
				return w * getSize().width / Math.abs(viewRight - viewLeft);
			}

			public float toHeight(float h)
			{
				return h * getSize().height / Math.abs(viewBottom - viewTop);
			}
		}


		//  subclass to draw a bar graph

		class GraphCanvas extends CoordCanvas
		{	  
			private double[] vals = null;

			public  void setValues(double[] vals)
			{
				this.vals = vals;
				repaint();
			}

			public  void paint(Graphics comp)
			{
				if (vals == null || vals.length < 1)
					return;

				// find maximum value
				double max = vals[0];
				for (int i = 0; i < vals.length; i++)
					if (vals[i] > max)
						max = vals[i];

				// set coordinate ranges
				this.setXRange(0F, (float)vals.length);
				this.setYRange((float)max, 0F);

				// draw the graph
				Graphics2D comp2D = (Graphics2D)comp;
				for (int i = 0; i < vals.length; i++)
				{
					Rectangle2D.Float remainingPrincipal = new Rectangle2D.Float(toX((float)i),
							toY((float)vals[i]), toWidth(1F), toHeight((float)vals[i]));
					comp2D.fill(remainingPrincipal);
				}
			}
			public static void main(String args[])
				{
			
			
			
				Mortgage_wk5 frame= new Mortgage_wk5();

			
		}
	}



Is This A Good Question/Topic? 0
  • +

Replies To: Reached end of file while parsing (Error)

#2 syfran  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 83
  • View blog
  • Posts: 1,103
  • Joined: 12-July 09

Re: Reached end of file while parsing (Error)

Posted 02 August 2009 - 03:33 PM

I'd say you have mismatched braces somewhere.
Was This Post Helpful? 0
  • +
  • -

#3 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 727
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: Reached end of file while parsing (Error)

Posted 02 August 2009 - 03:42 PM

yea, that's probably it..recheck your braces
Was This Post Helpful? 0
  • +
  • -

#4 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3105
  • View blog
  • Posts: 19,144
  • Joined: 14-September 07

Re: Reached end of file while parsing (Error)

Posted 02 August 2009 - 03:53 PM

I don't think I've ever gotten that error for any other reason other then braces.


Part of the issue lies with the inconsistency among your braces, some are

if()
{
}
p


while others are

if() {
}



Pick one and be consistent, it'll help.
Was This Post Helpful? 0
  • +
  • -

#5 Floridaboy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 02-August 09

Re: Reached end of file while parsing (Error)

Posted 02 August 2009 - 04:37 PM

OK guys i got it I can compile with zero errors but now when I use command prompt to run it it gives me this...
Exception in thread "main"java.lang.NoSuchMethodError: main
can any one give a hint on this
Was This Post Helpful? 0
  • +
  • -

#6 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 727
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: Reached end of file while parsing (Error)

Posted 02 August 2009 - 04:42 PM

the main method should be in the public class which is Mortgage_wk5 and not the GraphCanavas class

nevermind that..actually which class are you running?

actually my first guess was correct

This post has been edited by mostyfriedman: 02 August 2009 - 04:44 PM

Was This Post Helpful? 0
  • +
  • -

#7 Gloin  Icon User is offline

  • Expert Schmexpert...
  • member icon

Reputation: 235
  • View blog
  • Posts: 4,489
  • Joined: 04-August 08

Re: Reached end of file while parsing (Error)

Posted 02 August 2009 - 04:43 PM

Since you have a main method, it probably means it's just in the wrong place. Please post your entire code and it should be easy to find the problem.
Was This Post Helpful? 0
  • +
  • -

#8 syfran  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 83
  • View blog
  • Posts: 1,103
  • Joined: 12-July 09

Re: Reached end of file while parsing (Error)

Posted 02 August 2009 - 04:44 PM

Post your most current code, with correct indentation, my guess is brackets again.
Was This Post Helpful? 0
  • +
  • -

#9 Floridaboy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 02-August 09

Re: Reached end of file while parsing (Error)

Posted 02 August 2009 - 05:01 PM

[code]

import java.awt.*;
import java.text.NumberFormat;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Graphics;
import java.awt.geom.Rectangle2D;


public class mortgage_wk5 extends JFrame implements ActionListener
{
// Declare Labels
JLabel AmountLabel = new JLabel( "Principal Amount:$ " );
JLabel PaymentLabel = new JLabel( "Monthly Payment: " );
JLabel InterestLabel = new JLabel( "Interest Rate %: " );
JLabel TermLabel = new JLabel( "Length of Loan of Loan in Years: " );

// Declare Text Fields
JTextField mortgageAmount = new JTextField(7);
JTextField Payment = new JTextField(7);
JTextField InterestRate = new JTextField(3);
JTextField Term = new JTextField(3);


// Declare Buttons
JButton Loan7 = new JButton( "7 years at 5.35%" );
JButton Loan15 = new JButton( "15 years at 5.50%" );
JButton Loan30 = new JButton( "30 years at 5.75%" );
JButton ExitButton = new JButton( "Exit" );
JButton ClearButton = new JButton( "Clear All" );
JButton CalculateButton = new JButton( "Calculate Loan" );


// Declares Text Area and ScrollPane
JTextArea LoanPayments = new JTextArea(20,50);
JTextArea GraphArea = new JTextArea(19,50);
JScrollPane scroll = new JScrollPane(LoanPayments);


public mortgage_wk5()
{
//Frame, Panel, and Layout set up
super("mortgagecalcsr7");
setSize(900, 800);
setLocation(200, 0);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel pane = new JPanel(new GridLayout(3,1));

//Setup container and contents
Container grid = getContentPane();
grid.setLayout(new GridLayout(4,0,4,4));

pane.add(grid);
pane.add(scroll);
grid.add(AmountLabel);
grid.add(mortgageAmount);
grid.add(InterestLabel);
grid.add(InterestRate);
grid.add(TermLabel);
grid.add(Term);
grid.add(PaymentLabel);
grid.add(Payment);
grid.add(Loan7);
grid.add(Loan15);
grid.add(Loan30);
grid.add(CalculateButton);
grid.add(ClearButton);
grid.add(ExitButton);
Payment.setEditable(false);
setContentPane(pane);
setContentPane(pane);
setVisible(true);

//Adds Action Listeners
ExitButton.addActionListener(this);
ClearButton.addActionListener(this);
Loan7.addActionListener(this);
Loan15.addActionListener(this);
Loan30.addActionListener(this);
mortgageAmount.addActionListener(this);
InterestRate.addActionListener(this);
Term.addActionListener(this);
Payment.addActionListener(this);
CalculateButton.addActionListener(this);


}

public void actionPerformed(ActionEvent e) {
Object command = e.getSource();
if (command == ExitButton) {
System.exit(0); }
else if (command == Loan7) {
calcLoan(7, 5.35); }
else if (command == Loan15) {
calcLoan(15, 5.50); }
else if (command == Loan30) {
calcLoan(30, 5.75); }
else if (command == CalculateButton ) {
double terms = 0;
double rates = 0;
try {
terms = Double.parseDouble(Term.getText());
rates = Double.parseDouble(InterestRate.getText());
} catch (Exception ex) {
LoanPayments.setText("Invalid term or rate Amount");
return;

}

calcLoan(terms, rates); }
else if (command == ClearButton) {
mortgageAmount.setText("");
Payment.setText("");
InterestRate.setText("");
Term.setText("");
LoanPayments.setText("");

}

}

private void calcLoan(double terms, double rates) {
Term.setText(String.valueOf(terms) );
InterestRate.setText(String.valueOf(rates));
double amount = 0;
try {
amount = Double.parseDouble(mortgageAmount.getText());
//Parse text to
} catch (Exception ex) { LoanPayments.setText
("Invalid mortgage Amount");
return; }
double interestRate = rates;

// Sets interestRate amount
double intRate = (interestRate / 100) / 12;

// Calculates Interest Rate
// double loanTermMonths = terms;
// Calculates Loan Term in Months
int months = (int)terms * 12;

// Converts Loan Term to Months
double rate = (intRate / 12);

// Converts Annual interest rate to monthly interest rate
double payment = amount * intRate / (1 - (Math.pow(1/(1 + intRate), months)));

// Calculation for Monthly payment
double remainingPrincipal = amount;

// Sets Remaining Balance
double MonthlyInterest = 0;


// saves interest payment
double MonthlyAmt = 0;

// saves principal payment
//double x[] = new double[1]; x[0] = 0;
// Number formatter to format output in table
NumberFormat CurrencyFormatter = NumberFormat.getCurrencyInstance();
Payment.setText(CurrencyFormatter.format(payment));
LoanPayments.setText("Month\tPrincipal\tInterest\tEnding Balance\n");

// double[] values = new double[months];
// counting the month backward is confusing
// for(;months > 0; months -- )
int currentMonth = 0; while(currentMonth < months) {

//Append loop for mortgage detail in the text area
MonthlyInterest = (remainingPrincipal * intRate);

//Monthly Payment Toward Interest
MonthlyAmt = (payment - MonthlyInterest);

//Monthly Payment Toward Principal
remainingPrincipal = (remainingPrincipal - MonthlyAmt);

//Remaining loan Balance
// values[months-1] = remainingPrincipal;
LoanPayments.append((++currentMonth) + "\t" +
CurrencyFormatter.format(MonthlyAmt) + "\t" +
CurrencyFormatter.format(MonthlyInterest) + "\t" +
CurrencyFormatter.format(remainingPrincipal) + "\n");

GraphArea.append("" + remainingPrincipal);
}
}

public class GraphProgram extends JPanel

{
GraphCanvas graph = new GraphCanvas();

public GraphProgram()
{
setLayout(new BorderLayout());
setSize(300, 300);

add(graph, BorderLayout.CENTER);
}

public void setValues(double[] values) {
graph.setValues(values);
}
public class CoordCanvas extends Canvas
{
protected float viewLeft;
protected float viewRight;
protected float viewTop;
protected float viewBottom;

public void setXRange(float left, float right)
{
viewLeft = left;
viewRight = right;
}

public void setYRange(float top, float bottom)
{
viewTop = top;
viewBottom = bottom;
}

public float toX(float x)
{
return (x - viewLeft) * getSize().width / (viewRight - viewLeft);
}

public float toY(float y)
{
return (y - viewTop) * getSize().height / (viewBottom - viewTop);
}

public float toWidth(float w)
{
return w * getSize().width / Math.abs(viewRight - viewLeft);
}

public float toHeight(float h)
{
return h * getSize().height / Math.abs(viewBottom - viewTop);
}
}


// subclass to draw a bar graph

class GraphCanvas extends CoordCanvas
{
private double[] vals = null;

public void setValues(double[] vals)
{
this.vals = vals;
repaint();
}

public void paint(Graphics comp)
{
if (vals == null || vals.length < 1)
return;

// find maximum value
double max = vals[0];
for (int i = 0; i < vals.length; i++)
if (vals[i] > max)
max = vals[i];

// set coordinate ranges
this.setXRange(0F, (float)vals.length);
this.setYRange((float)max, 0F);

// draw the graph
Graphics2D comp2D = (Graphics2D)comp;
for (int i = 0; i < vals.length; i++)
{
Rectangle2D.Float remainingPrincipal = new Rectangle2D.Float(toX((float)i),
toY((float)vals[i]), toWidth(1F), toHeight((float)vals[i]));
comp2D.fill(remainingPrincipal);
}
}
public void main(String args[])
{



mortgage_wk5 frame= new mortgage_wk5();


}
}
}
}
[code]

This post has been edited by Floridaboy: 02 August 2009 - 05:01 PM

Was This Post Helpful? 0
  • +
  • -

#10 Floridaboy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 02-August 09

Re: Reached end of file while parsing (Error)

Posted 02 August 2009 - 05:08 PM

import java.awt.*;
import java.text.NumberFormat;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Graphics;
import java.awt.geom.Rectangle2D;


public class Mortgage_wk5 extends JFrame implements ActionListener
{
	// Declare Labels
	JLabel AmountLabel = new JLabel( "Principal Amount:$ " );
	JLabel PaymentLabel = new JLabel( "Monthly Payment: " );
	JLabel InterestLabel = new JLabel( "Interest Rate %: " );
	JLabel TermLabel = new JLabel( "Length of Loan of Loan in Years: " );

	// Declare Text Fields
	JTextField mortgageAmount = new JTextField(7);
	JTextField Payment = new JTextField(7);
	JTextField InterestRate = new JTextField(3);
	JTextField Term = new JTextField(3);


	// Declare Buttons
	JButton Loan7 = new JButton( "7 years at 5.35%" );
	JButton Loan15 = new JButton( "15 years at 5.50%" );
	JButton Loan30 = new JButton( "30 years at 5.75%" );
	JButton ExitButton = new JButton( "Exit" );
	JButton ClearButton = new JButton( "Clear All" );
	JButton CalculateButton = new JButton( "Calculate Loan" );


	// Declares Text Area and ScrollPane
	JTextArea LoanPayments = new JTextArea(20,50);
	JTextArea GraphArea = new JTextArea(19,50);
	JScrollPane scroll = new JScrollPane(LoanPayments);


	public Mortgage_wk5()
	{
		//Frame, Panel, and Layout set up
		super("mortgagecalcsr7");
		setSize(900, 800);
		setLocation(200, 0);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		JPanel pane = new JPanel(new GridLayout(3,1));

		//Setup container and contents
		Container grid = getContentPane();
		grid.setLayout(new GridLayout(4,0,4,4));

		pane.add(grid);
		pane.add(scroll);
		grid.add(AmountLabel);
		grid.add(mortgageAmount);
		grid.add(InterestLabel);
		grid.add(InterestRate);
		grid.add(TermLabel);
		grid.add(Term);
		grid.add(PaymentLabel);
		grid.add(Payment);
		grid.add(Loan7);
		grid.add(Loan15);
		grid.add(Loan30);
		grid.add(CalculateButton);
		grid.add(ClearButton);
		grid.add(ExitButton);
		Payment.setEditable(false);
		setContentPane(pane);
		setContentPane(pane);
		setVisible(true);

		//Adds Action Listeners
		ExitButton.addActionListener(this);
		ClearButton.addActionListener(this);
		Loan7.addActionListener(this);
		Loan15.addActionListener(this);
		Loan30.addActionListener(this);
		mortgageAmount.addActionListener(this);
		InterestRate.addActionListener(this);
		Term.addActionListener(this);
		Payment.addActionListener(this);
		CalculateButton.addActionListener(this);


	}

	public void actionPerformed(ActionEvent e) {
		Object command = e.getSource();
		if (command == ExitButton) {
			System.exit(0);	 }
		else if (command == Loan7) {
			calcLoan(7, 5.35);	 }
		else if (command == Loan15) {
			calcLoan(15, 5.50);	 }
		else if (command == Loan30) {
			calcLoan(30, 5.75);	 }
		else if (command == CalculateButton ) {
			double terms = 0;
			double rates = 0;
			try {
				terms = Double.parseDouble(Term.getText());
				rates = Double.parseDouble(InterestRate.getText());
			} catch (Exception ex) {
				LoanPayments.setText("Invalid term or rate Amount");
				return;

			}

			calcLoan(terms, rates);	 }
		else if (command == ClearButton) {
			mortgageAmount.setText("");
			Payment.setText("");
			InterestRate.setText("");
			Term.setText("");
			LoanPayments.setText("");

		}

	}

	private void calcLoan(double terms, double rates) {
		Term.setText(String.valueOf(terms) );
		InterestRate.setText(String.valueOf(rates));
		double amount = 0;
		try {
			amount = Double.parseDouble(mortgageAmount.getText());
			//Parse text to
		}	 catch (Exception ex) {		  LoanPayments.setText
			("Invalid mortgage Amount");
		return;	 }
		double interestRate = rates;

		// Sets interestRate amount
		double intRate = (interestRate / 100) / 12;

		// Calculates Interest Rate
		// double loanTermMonths = terms;
		// Calculates Loan Term in Months
		int months = (int)terms * 12;

		// Converts Loan Term to Months
		double rate = (intRate / 12);

		// Converts Annual interest rate to monthly interest rate
		double payment = amount * intRate / (1 - (Math.pow(1/(1 + intRate), months)));

		// Calculation for Monthly payment
		double remainingPrincipal = amount;

		// Sets Remaining Balance
		double MonthlyInterest = 0;


		// saves interest payment
		double MonthlyAmt = 0;

		// saves principal payment
		//double x[] = new double[1]; x[0] = 0;
		// Number formatter to format output in table
		NumberFormat CurrencyFormatter = NumberFormat.getCurrencyInstance();
		Payment.setText(CurrencyFormatter.format(payment));
		LoanPayments.setText("Month\tPrincipal\tInterest\tEnding Balance\n");

		// double[] values = new double[months];
		// counting the month backward is confusing
		// for(;months > 0; months -- )
		int currentMonth = 0;	 while(currentMonth < months) {

			//Append loop for mortgage detail in the text area
			MonthlyInterest = (remainingPrincipal * intRate);

			//Monthly Payment Toward Interest
			MonthlyAmt = (payment - MonthlyInterest);

			//Monthly Payment Toward Principal
			remainingPrincipal = (remainingPrincipal - MonthlyAmt);

			//Remaining loan Balance
			// values[months-1] = remainingPrincipal;
			LoanPayments.append((++currentMonth) + "\t" +
					CurrencyFormatter.format(MonthlyAmt) + "\t" +
					CurrencyFormatter.format(MonthlyInterest) + "\t" +
					CurrencyFormatter.format(remainingPrincipal) + "\n");

			GraphArea.append("" + remainingPrincipal);
		}
	}

	public class GraphProgram extends JPanel

	{
		GraphCanvas graph = new GraphCanvas();

		public GraphProgram()
		{
			setLayout(new BorderLayout());
			setSize(300, 300);

			add(graph, BorderLayout.CENTER);
		}

		public  void setValues(double[] values) {
			graph.setValues(values);
		}
		public class CoordCanvas extends Canvas
		{
			protected float viewLeft;
			protected float viewRight;
			protected float viewTop;
			protected float viewBottom;

			public void setXRange(float left, float right)
			{
				viewLeft = left;
				viewRight = right;
			}

			public void setYRange(float top, float bottom)
			{
				viewTop = top;
				viewBottom = bottom;
			}

			public float toX(float x)
			{
				return (x - viewLeft) * getSize().width / (viewRight - viewLeft);
			}

			public float toY(float y)
			{
				return (y - viewTop) * getSize().height / (viewBottom - viewTop);
			}

			public float toWidth(float w)
			{
				return w * getSize().width / Math.abs(viewRight - viewLeft);
			}

			public float toHeight(float h)
			{
				return h * getSize().height / Math.abs(viewBottom - viewTop);
			}
		}


		//  subclass to draw a bar graph

		class GraphCanvas extends CoordCanvas
		{
			private double[] vals = null;

			public  void setValues(double[] vals)
			{
				this.vals = vals;
				repaint();
			}

			public  void paint(Graphics comp)
			{
				if (vals == null || vals.length < 1)
					return;

				// find maximum value
				double max = vals[0];
				for (int i = 0; i < vals.length; i++)
					if (vals[i] > max)
						max = vals[i];

				// set coordinate ranges
				this.setXRange(0F, (float)vals.length);
				this.setYRange((float)max, 0F);

				// draw the graph
				Graphics2D comp2D = (Graphics2D)comp;
				for (int i = 0; i < vals.length; i++)
				{
					Rectangle2D.Float remainingPrincipal = new Rectangle2D.Float(toX((float)i),
							toY((float)vals[i]), toWidth(1F), toHeight((float)vals[i]));
					comp2D.fill(remainingPrincipal);
				}
			}
			public void main(String args[])
				{



				Mortgage_wk5 frame= new Mortgage_wk5();


}
		}
	}
}


Was This Post Helpful? 0
  • +
  • -

#11 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 727
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: Reached end of file while parsing (Error)

Posted 02 August 2009 - 05:13 PM

well depending on the class you're running, the main method has to be in that class
Was This Post Helpful? 0
  • +
  • -

#12 Floridaboy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 02-August 09

Re: Reached end of file while parsing (Error)

Posted 02 August 2009 - 05:14 PM

fried man can you give me an example its been a long day with this code if i can not get it here i might have to start over.
Was This Post Helpful? 0
  • +
  • -

#13 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 727
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: Reached end of file while parsing (Error)

Posted 02 August 2009 - 05:32 PM

are you compiling and executing from command line or from an IDE?
Was This Post Helpful? 0
  • +
  • -

#14 Floridaboy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 02-August 09

Re: Reached end of file while parsing (Error)

Posted 02 August 2009 - 05:36 PM

i do the compling in jcreator and then i do the compile and run in command prompt like we were told. why do you see the error in mine
Was This Post Helpful? 0
  • +
  • -

#15 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 727
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: Reached end of file while parsing (Error)

Posted 02 August 2009 - 05:39 PM

ok when you run you're program what do you write in the command line?? i believe you are writing
java Mortgage_wk5

am i correct??.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2