End of file while parsing problem

one error but can not find where the error is

Page 1 of 1

12 Replies - 719 Views - Last Post: 26 July 2009 - 07:43 PM Rate Topic: -----

#1 camaro  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 26-July 09

End of file while parsing problem

Posted 26 July 2009 - 04:36 PM

I am getting an error says that I have reached end offile while parsing. can any one help me with this

/*

- 7 year at 5.35%
- 15 year at 5.5 %
- 30 year at 5.75%
 */

//opening libraries
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.DecimalFormat;
import javax.swing.JOptionPane;

//declaring content
public class MC4 extends JFrame implements ActionListener
{
	private static MC4();

				  //adding initial selection options via RadioButtons
	 JPanel row_aa = new JPanel();
	 JRadioButton opt1 = new JRadioButton ("Manual Input", true);
	 JRadioButton opt2 = new JRadioButton ("Menu Selections", false);

			 //content Buttons, Panels, Labels, and TextFields

	 JPanel row_a = new JPanel();
	 JLabel amntLabel = new JLabel();

	 JTextField loanField = new JTextField();
	 JLabel loan2Label = new JLabel ();
	 JPanel row_b = new JPanel();

	 JPanel row_b1 = new JPanel();
			 JLabel termLabel = new JLabel ();  //term
			 JTextField termField = new JTextField(4);

			 JPanel row_b2 = new JPanel();
			 JLabel int_entryLabel = new JLabel ();  //interest
			 JTextField int_entryField = new JTextField(3);

	 JComboBox options = new JComboBox();
	 JLabel optionsLabel = new JLabel();

	 JPanel row_c = new JPanel();
	 JButton calButton = new JButton();
	 JButton resetButton = new JButton();
	 JButton endButton = new JButton();

	 JPanel row_d = new JPanel();
	 JLabel paymtLabel = new JLabel();
	 JTextField paymtField = new JTextField();

	 JPanel row_e = new JPanel();
	 JLabel outputLabel = new JLabel();

	 JPanel row_f = new JPanel();
	 JTextArea opField = new JTextArea(5, 55);


	 JScrollPane scrollPane = new JScrollPane(opField,
			   ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
			   ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

		  ButtonGroup radioSelect = new ButtonGroup();
	private String i;

//setting format of GUI layout
	{
	 {

		  //main GUI Dimensions  super("MC4- Loan Calculator with Preselected or Customized Values");
		  setSize(900, 265);
		  new GridLayout(6, 4, 10, 10);
		  FlowLayout flowCenter = new FlowLayout(FlowLayout.CENTER);
		  FlowLayout flow = new FlowLayout(FlowLayout.LEFT);

		  Container pane = getContentPane();
		  pane.setLayout(flow);


		  setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		  setVisible(true);

							  //setting actionListeners for Fields and Buttons
		  loanField.addActionListener(this);
		  termField.addActionListener(this);
		  int_entryField.addActionListener(this);
		  options.addActionListener(this);
		  calButton.addActionListener(this);
		  resetButton.addActionListener(this);
		  endButton.addActionListener(this);
		  opt1.addActionListener(this);
		  opt2.addActionListener(this);


							  //layout for mortgage amount entry
		  row_a.setLayout(flow);
		  amntLabel.setText("Please Enter Loan Amount w/o Commas:");
		  row_a.add(amntLabel);
		  row_a.add(loanField);
		  radioSelect.add(opt1);
		  radioSelect.add(opt2);
		  pane.add(row_a);


							  //layout for options
		  options.addItem("7 years at 5.35%");
		  options.addItem("15 years at 5.5%");
		  options.addItem("30 years at 5.75%");
		  options.setEnabled(false);

		  row_b.setLayout(flow);
		  row_b.add(options);
		  pane.add(row_b);

		  row_b1.setLayout(flow);
		  termLabel.setText("Term in Years");
		  row_b1.add(termLabel);
		  row_b1.add(termField);
		  pane.add(row_b1);

		  row_b2.setLayout(flow);
		  int_entryLabel.setText("Interest %");
		  row_b2.add(int_entryLabel);
		  row_b2.add(int_entryField);
		  pane.add(row_b2);


							  //layout for buttons to calculate, Reset, and End
							  row_c.setLayout(flow);
		  calButton.setText("Calculate");
		  calButton.setBackground(Color.green);
		  row_c.add(calButton);
		  resetButton.setText("Reset");
		  resetButton.setBackground(Color.yellow);
		  row_c.add(resetButton);
		  endButton.setText("End");
		  endButton.setBackground(Color.red);
		  row_c.add(endButton);
		  pane.add(row_c);

							  //layout for section that shows the monthly payment amount
		  row_d.setLayout(flow);
		  paymtLabel.setText("Monthly Payment Amount:");
		  row_d.add(paymtLabel);
		  row_d.add(paymtField);
		  pane.add(row_d);

							  //layout for loan amoritzation table
		  row_e.setLayout(flow);
		  outputLabel.setText("Loan Amoritization Table");
		  row_e.add(outputLabel);
		  pane.add(row_e);

		  row_f.setLayout(flowCenter);
		  opField.setLineWrap(true);
		  opField.setWrapStyleWord(true);
		  opField.setEditable(true);
		  row_f.add(scrollPane);
		  pane.add(row_f);


	 }


//adding actionEvents for Buttons
addActionListener(
	new ActionAdapter()
	 {
	 public void actionPerformed(ActionEvent gotevent)
	 {
		  Object source = event.getSource();
		  if (source == calButton) {
			   startCalculations();

		  }
		  if (source == resetButton) {
			   reset();

		  }
		  if (source == endButton) {
			   end();

		  }
		  if (source == opt1){

			  options.setEnabled(false);
				   termField.setEnabled(true);
			  termField.setEditable(true);
			  int_entryField.setEnabled(true);
			  int_entryField.setEditable(true);
			  }

			  if (source == opt2){

			  options.setEnabled(true);
			  termField.setEnabled(false);
			  termField.setEditable(false);
			  int_entryField.setEnabled(false);
			  int_entryField.setEditable(false);
			  }

		 }
//formulas for monthly payment
	 void startCalculations() {

		  Thread thisThread = Thread.currentThread();
		  DecimalFormat twodigits = new DecimalFormat("#,###.00");

		  double amt = 0;   //amount of loan
		  double trm = 0;   //variable for term of loan
		  double intrst = 0;  //variable for interest amount of loan
		  double moIn = 0;  //variable for monthly payment for formula
		  double moTrm = 0; //variable for monthly term for formula
		  double prin = 0;  // variable for principle
		  double paymt = 0;  //variable for payment
		  double newPrin = amt;
		  boolean Exception = false;


		  try {
			   amt = Double.parseDouble(loanField.getText());
		  } catch (DecimalFormatException e) {
			   JOptionPane.showMessageDialog(null, "Please Do Not Use Commas","Message Dialog", JOptionPane.PLAIN_MESSAGE);
			   loanField.setText(null);

		  }

		  if (opt2.isSelected())
		  {
			  if(options.getSelectedIndex() == 0)
			  {
		  trm=7;
		  intrst=5.35;
		  }
			  else if(options.getSelectedIndex() ==1)
			  {
					trm=15;
					intrst=5.5;
			  }
			  else
			  {
					trm=30;
									intrst=5.75;
							  }
							  }
							  else
							  {
		 try
					{
				   trm = Double.parseDouble(termField.getText());
					}
					catch (DecimalFormatException e)
					{
					JOptionPane.showMessageDialog(this,"Enter amounts greater than zero","Please enter new amount",JOptionPane.ERROR_MESSAGE);
					Exception=true;
					termField.setText(null);
			  }
			  try
			  {
					intrst= Double.parseDouble(int_entryField.getText());
			  }
			  catch (DecimalFormatException e)
			  {
					JOptionPane.showMessageDialog(this,"Enter amount greater than zero and with no % sign","Please enter new amount",JOptionPane.ERROR_MESSAGE);
					Exception=true;
					int_entryField.setText(null);
			  }
		}


//output for Loan Amoritzation Table
		  if (amt > 0 && trm > 0 && intrst > 0) {
			   amt = Double.parseDouble(loanField.getText());
			   moIn = (intrst / 12) / 100;
			   moTrm = trm * 12;
			   paymt = amt * (moIn / (1 - java.lang.Math.pow((1 + moIn), (-moTrm))));

			   paymtField.setText("" + Decimal.format(paymt));

			   opField.append("Payment#");
			   opField.append("			");
			   opField.append("Payment Amount");
			   opField.append("		   ");
			   opField.append("Interest");
			   opField.append("		   ");
			   opField.append("Principle Reduction");
			   opField.append("		   ");
			   opField.append("Remaining Balance");
			   opField.append("	  \n");




			   for(int i = 0; i <= moTrm; i++)
			   {
					double newIn = moIn * newPrin;
					double reduct = paymt - newIn;
					newPrin = newPrin - reduct;

				  }

					opField.append("	" + i);
					opField.append("" + Decimal.format(paymt));
					opField.append("" + Decimal.format(newIn));
					opField.append("" + Decimal.format(reduct));
					opField.append("" + Decimal.format(newPrin) + "\n");


			  }

					  if((amt <= 0 || trm <= 0 || intrst <= 0) && (Exception == false))
					  {
			   JOptionPane.showMessageDialog(null, "Please Enter Positive Numbers Only.",
						 "Message Dialog", JOptionPane.PLAIN_MESSAGE);
			   if(amt <= 0) {
				loanField.setText(null);
			}
		  }
		}

// resets GUI for another calculation
	 void reset(); {

		  loanField.setText(null);
		  paymtField.setText(null);
		  }
}
//End of Program

This post has been edited by pbl: 26 July 2009 - 07:11 PM


Is This A Good Question/Topic? 0
  • +

Replies To: End of file while parsing problem

#2 nick2price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 562
  • View blog
  • Posts: 2,826
  • Joined: 23-November 07

Re: End of file while parsing problem

Posted 26 July 2009 - 04:37 PM

That error means your missing a } at the end of your file
Was This Post Helpful? 0
  • +
  • -

#3 camaro  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 26-July 09

Re: End of file while parsing problem

Posted 26 July 2009 - 04:38 PM

View Postnick2price, on 26 Jul, 2009 - 03:37 PM, said:

That error means your missing a } at the end of your file

I understand that but i have looked over it 5 times and can not find one missing or in the wrong place
Was This Post Helpful? 0
  • +
  • -

#4 camaro  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 26-July 09

Re: End of file while parsing problem

Posted 26 July 2009 - 04:49 PM

View Postcamaro, on 26 Jul, 2009 - 03:38 PM, said:

View Postnick2price, on 26 Jul, 2009 - 03:37 PM, said:

That error means your missing a } at the end of your file

I understand that but i have looked over it 5 times and can not find one missing or in the wrong place



Can anyone help me with the one error
Was This Post Helpful? 0
  • +
  • -

#5 camaro  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 26-July 09

Re: End of file while parsing problem

Post icon  Posted 26 July 2009 - 05:10 PM

 getting an error says that I have reached end offile while parsing. can any one help me with this

CODE/*

- 7 year at 5.35%
- 15 year at 5.5 %
- 30 year at 5.75%
*/

//opening libraries
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.DecimalFormat;
import javax.swing.JOptionPane;

//declaring content
public class MC4 extends JFrame implements ActionListener
{
	private static MC4();

				  //adding initial selection options via RadioButtons
	 JPanel row_aa = new JPanel();
	 JRadioButton opt1 = new JRadioButton ("Manual Input", true);
	 JRadioButton opt2 = new JRadioButton ("Menu Selections", false);

			 //content Buttons, Panels, Labels, and TextFields

	 JPanel row_a = new JPanel();
	 JLabel amntLabel = new JLabel();

	 JTextField loanField = new JTextField();
	 JLabel loan2Label = new JLabel ();
	 JPanel row_b = new JPanel();

	 JPanel row_b1 = new JPanel();
			 JLabel termLabel = new JLabel ();  //term
			 JTextField termField = new JTextField(4);

			 JPanel row_b2 = new JPanel();
			 JLabel int_entryLabel = new JLabel ();  //interest
			 JTextField int_entryField = new JTextField(3);

	 JComboBox options = new JComboBox();
	 JLabel optionsLabel = new JLabel();

	 JPanel row_c = new JPanel();
	 JButton calButton = new JButton();
	 JButton resetButton = new JButton();
	 JButton endButton = new JButton();

	 JPanel row_d = new JPanel();
	 JLabel paymtLabel = new JLabel();
	 JTextField paymtField = new JTextField();

	 JPanel row_e = new JPanel();
	 JLabel outputLabel = new JLabel();

	 JPanel row_f = new JPanel();
	 JTextArea opField = new JTextArea(5, 55);


	 JScrollPane scrollPane = new JScrollPane(opField,
			   ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
			   ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

		  ButtonGroup radioSelect = new ButtonGroup();
	private String i;

//setting format of GUI layout
	{
	 {

		  //main GUI Dimensions  super("MC4- Loan Calculator with Preselected or Customized Values");
		  setSize(900, 265);
		  new GridLayout(6, 4, 10, 10);
		  FlowLayout flowCenter = new FlowLayout(FlowLayout.CENTER);
		  FlowLayout flow = new FlowLayout(FlowLayout.LEFT);

		  Container pane = getContentPane();
		  pane.setLayout(flow);


		  setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		  setVisible(true);

							  //setting actionListeners for Fields and Buttons
		  loanField.addActionListener(this);
		  termField.addActionListener(this);
		  int_entryField.addActionListener(this);
		  options.addActionListener(this);
		  calButton.addActionListener(this);
		  resetButton.addActionListener(this);
		  endButton.addActionListener(this);
		  opt1.addActionListener(this);
		  opt2.addActionListener(this);


							  //layout for mortgage amount entry
		  row_a.setLayout(flow);
		  amntLabel.setText("Please Enter Loan Amount w/o Commas:");
		  row_a.add(amntLabel);
		  row_a.add(loanField);
		  radioSelect.add(opt1);
		  radioSelect.add(opt2);
		  pane.add(row_a);


							  //layout for options
		  options.addItem("7 years at 5.35%");
		  options.addItem("15 years at 5.5%");
		  options.addItem("30 years at 5.75%");
		  options.setEnabled(false);

		  row_b.setLayout(flow);
		  row_b.add(options);
		  pane.add(row_b);

		  row_b1.setLayout(flow);
		  termLabel.setText("Term in Years");
		  row_b1.add(termLabel);
		  row_b1.add(termField);
		  pane.add(row_b1);

		  row_b2.setLayout(flow);
		  int_entryLabel.setText("Interest %");
		  row_b2.add(int_entryLabel);
		  row_b2.add(int_entryField);
		  pane.add(row_b2);


							  //layout for buttons to calculate, Reset, and End
							  row_c.setLayout(flow);
		  calButton.setText("Calculate");
		  calButton.setBackground(Color.green);
		  row_c.add(calButton);
		  resetButton.setText("Reset");
		  resetButton.setBackground(Color.yellow);
		  row_c.add(resetButton);
		  endButton.setText("End");
		  endButton.setBackground(Color.red);
		  row_c.add(endButton);
		  pane.add(row_c);

							  //layout for section that shows the monthly payment amount
		  row_d.setLayout(flow);
		  paymtLabel.setText("Monthly Payment Amount:");
		  row_d.add(paymtLabel);
		  row_d.add(paymtField);
		  pane.add(row_d);

							  //layout for loan amoritzation table
		  row_e.setLayout(flow);
		  outputLabel.setText("Loan Amoritization Table");
		  row_e.add(outputLabel);
		  pane.add(row_e);

		  row_f.setLayout(flowCenter);
		  opField.setLineWrap(true);
		  opField.setWrapStyleWord(true);
		  opField.setEditable(true);
		  row_f.add(scrollPane);
		  pane.add(row_f);


	 }


//adding actionEvents for Buttons
addActionListener(
	new ActionAdapter()
	 {
	 public void actionPerformed(ActionEvent gotevent)
	 {
		  Object source = event.getSource();
		  if (source == calButton) {
			   startCalculations();

		  }
		  if (source == resetButton) {
			   reset();

		  }
		  if (source == endButton) {
			   end();

		  }
		  if (source == opt1){

			  options.setEnabled(false);
				   termField.setEnabled(true);
			  termField.setEditable(true);
			  int_entryField.setEnabled(true);
			  int_entryField.setEditable(true);
			  }

			  if (source == opt2){

			  options.setEnabled(true);
			  termField.setEnabled(false);
			  termField.setEditable(false);
			  int_entryField.setEnabled(false);
			  int_entryField.setEditable(false);
			  }

		 }
//formulas for monthly payment
	 void startCalculations() {

		  Thread thisThread = Thread.currentThread();
		  DecimalFormat twodigits = new DecimalFormat("#,###.00");

		  double amt = 0;   //amount of loan
		  double trm = 0;   //variable for term of loan
		  double intrst = 0;  //variable for interest amount of loan
		  double moIn = 0;  //variable for monthly payment for formula
		  double moTrm = 0; //variable for monthly term for formula
		  double prin = 0;  // variable for principle
		  double paymt = 0;  //variable for payment
		  double newPrin = amt;
		  boolean Exception = false;


		  try {
			   amt = Double.parseDouble(loanField.getText());
		  } catch (DecimalFormatException e) {
			   JOptionPane.showMessageDialog(null, "Please Do Not Use Commas","Message Dialog", JOptionPane.PLAIN_MESSAGE);
			   loanField.setText(null);

		  }

		  if (opt2.isSelected())
		  {
			  if(options.getSelectedIndex() == 0)
			  {
		  trm=7;
		  intrst=5.35;
		  }
			  else if(options.getSelectedIndex() ==1)
			  {
					trm=15;
					intrst=5.5;
			  }
			  else
			  {
					trm=30;
									intrst=5.75;
							  }
							  }
							  else
							  {
		 try
					{
				   trm = Double.parseDouble(termField.getText());
					}
					catch (DecimalFormatException e)
					{
					JOptionPane.showMessageDialog(this,"Enter amounts greater than zero","Please enter new amount",JOptionPane.ERROR_MESSAGE);
					Exception=true;
					termField.setText(null);
			  }
			  try
			  {
					intrst= Double.parseDouble(int_entryField.getText());
			  }
			  catch (DecimalFormatException e)
			  {
					JOptionPane.showMessageDialog(this,"Enter amount greater than zero and with no % sign","Please enter new amount",JOptionPane.ERROR_MESSAGE);
					Exception=true;
					int_entryField.setText(null);
			  }
		}


//output for Loan Amoritzation Table
		  if (amt > 0 && trm > 0 && intrst > 0) {
			   amt = Double.parseDouble(loanField.getText());
			   moIn = (intrst / 12) / 100;
			   moTrm = trm * 12;
			   paymt = amt * (moIn / (1 - java.lang.Math.pow((1 + moIn), (-moTrm))));

			   paymtField.setText("" + Decimal.format(paymt));

			   opField.append("Payment#");
			   opField.append("			");
			   opField.append("Payment Amount");
			   opField.append("		   ");
			   opField.append("Interest");
			   opField.append("		   ");
			   opField.append("Principle Reduction");
			   opField.append("		   ");
			   opField.append("Remaining Balance");
			   opField.append("	  \n");




			   for(int i = 0; i <= moTrm; i++)
			   {
					double newIn = moIn * newPrin;
					double reduct = paymt - newIn;
					newPrin = newPrin - reduct;

				  }

					opField.append("	" + i);
					opField.append("" + Decimal.format(paymt));
					opField.append("" + Decimal.format(newIn));
					opField.append("" + Decimal.format(reduct));
					opField.append("" + Decimal.format(newPrin) + "\n");


			  }

					  if((amt <= 0 || trm <= 0 || intrst <= 0) && (Exception == false))
					  {
			   JOptionPane.showMessageDialog(null, "Please Enter Positive Numbers Only.",
						 "Message Dialog", JOptionPane.PLAIN_MESSAGE);
			   if(amt <= 0) {
				loanField.setText(null);
			}
		  }
		}

// resets GUI for another calculation
	 void reset(); {

		  loanField.setText(null);
		  paymtField.setText(null);
		  }
}
//End of Program


Was This Post Helpful? 0
  • +
  • -

#6 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8342
  • View blog
  • Posts: 31,880
  • Joined: 06-March 08

Re: End of file while parsing problem

Posted 26 July 2009 - 05:45 PM

Please have a more meaningful topic name |Java question" on a forum dedicated to answer questions on Java is kind of uselesss

1) new ActionAdapter()

you probably mean ActionListener()

2) you have 3 } missinbg closing your code

3) you cannot define a variable like that in the middle of a method

private String i;

4) event.getSource();
probably mean gotevent

			addActionListener(
					new ActionListener()
					{
						public void actionPer



an online listener cannot reference instance variable of its class until they are final so:
-calcbutton, resetButton, ... will have to be declared final or use another mechanism

This post has been edited by pbl: 26 July 2009 - 06:02 PM

Was This Post Helpful? 1
  • +
  • -

#7 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8342
  • View blog
  • Posts: 31,880
  • Joined: 06-March 08

Re: End of file while parsing problem

Posted 26 July 2009 - 06:11 PM

private static MC4(); <----- this ; might explain a lot of your errors

Duplicated topics merged
Avoid double topics :angry:
Have no time to answer all topics no need to ask them twice
Was This Post Helpful? 0
  • +
  • -

#8 camaro  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 26-July 09

Re: End of file while parsing problem

Posted 26 July 2009 - 06:21 PM

there is only one error and it says that i have a open } or one missing but i can not find one either missing or extra

View Postpbl, on 26 Jul, 2009 - 05:11 PM, said:

private static MC4(); <----- this ; might explain a lot of your errors

Duplicated topics merged
Avoid double topics :angry:
Have no time to answer all topics no need to ask them twice

Was This Post Helpful? 0
  • +
  • -

#9 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8342
  • View blog
  • Posts: 31,880
  • Joined: 06-March 08

Re: End of file while parsing problem

Posted 26 July 2009 - 06:23 PM

You haven't still renamed your topic thow

Go to your first post
FULL edit edit it
Change topic title or I'll close it :)
Was This Post Helpful? 0
  • +
  • -

#10 camaro  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 26-July 09

Re: End of file while parsing problem

Posted 26 July 2009 - 07:06 PM

View Postpbl, on 26 Jul, 2009 - 05:23 PM, said:

You haven't still renamed your topic thow

Go to your first post
FULL edit edit it
Change topic title or I'll close it :)

ok i fixed it. is there a way that you can guide me.
Was This Post Helpful? 0
  • +
  • -

#11 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8342
  • View blog
  • Posts: 31,880
  • Joined: 06-March 08

Re: End of file while parsing problem

Posted 26 July 2009 - 07:14 PM

OK, your new topic title was not very much more usefull
but at least you did an effort
So I renamed your topic to a real meningfull title
and now repost your code what you are at and because you made an effort I'll have a look at it :)
Was This Post Helpful? 0
  • +
  • -

#12 camaro  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 26-July 09

Re: End of file while parsing problem

Posted 26 July 2009 - 07:17 PM

ok thank you you are the man

- 7 year at 5.35%
- 15 year at 5.5 %
- 30 year at 5.75%
 */

//opening libraries
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.DecimalFormat;
import javax.swing.JOptionPane;

//declaring content
public class MC4 extends JFrame implements ActionListener
{
  

				  //adding initial selection options via RadioButtons
	 JPanel row_aa = new JPanel();
	 JRadioButton opt1 = new JRadioButton ("Manual Input", true);
	 JRadioButton opt2 = new JRadioButton ("Menu Selections", false);

			 //content Buttons, Panels, Labels, and TextFields

	 JPanel row_a = new JPanel();
	 JLabel amntLabel = new JLabel();

	 JTextField loanField = new JTextField();
	 JLabel loan2Label = new JLabel ();
	 JPanel row_b = new JPanel();

	 JPanel row_b1 = new JPanel();
			 JLabel termLabel = new JLabel ();  //term
			 JTextField termField = new JTextField(4);

			 JPanel row_b2 = new JPanel();
			 JLabel int_entryLabel = new JLabel ();  //interest
			 JTextField int_entryField = new JTextField(3);

	 JComboBox options = new JComboBox();
	 JLabel optionsLabel = new JLabel();

	 JPanel row_c = new JPanel();
	 JButton calButton = new JButton();
	 JButton resetButton = new JButton();
	 JButton endButton = new JButton();

	 JPanel row_d = new JPanel();
	 JLabel paymtLabel = new JLabel();
	 JTextField paymtField = new JTextField();

	 JPanel row_e = new JPanel();
	 JLabel outputLabel = new JLabel();

	 JPanel row_f = new JPanel();
	 JTextArea opField = new JTextArea(5, 55);


	 JScrollPane scrollPane = new JScrollPane(opField,
			   ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
			   ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

		  ButtonGroup radioSelect = new ButtonGroup();
	private String i;

//setting format of GUI layout
	{
	 {

		  //main GUI Dimensions  super("MC4- Loan Calculator with Preselected or Customized Values");
		  setSize(900, 265);
		  new GridLayout(6, 4, 10, 10);
		  FlowLayout flowCenter = new FlowLayout(FlowLayout.CENTER);
		  FlowLayout flow = new FlowLayout(FlowLayout.LEFT);

		  Container pane = getContentPane();
		  pane.setLayout(flow);


		  setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		  setVisible(true);

							  //setting actionListeners for Fields and Buttons
		  loanField.addActionListener(this);
		  termField.addActionListener(this);
		  int_entryField.addActionListener(this);
		  options.addActionListener(this);
		  calButton.addActionListener(this);
		  resetButton.addActionListener(this);
		  endButton.addActionListener(this);
		  opt1.addActionListener(this);
		  opt2.addActionListener(this);


							  //layout for mortgage amount entry
		  row_a.setLayout(flow);
		  amntLabel.setText("Please Enter Loan Amount w/o Commas:");
		  row_a.add(amntLabel);
		  row_a.add(loanField);
		  radioSelect.add(opt1);
		  radioSelect.add(opt2);
		  pane.add(row_a);


							  //layout for options
		  options.addItem("7 years at 5.35%");
		  options.addItem("15 years at 5.5%");
		  options.addItem("30 years at 5.75%");
		  options.setEnabled(false);

		  row_b.setLayout(flow);
		  row_b.add(options);
		  pane.add(row_b);

		  row_b1.setLayout(flow);
		  termLabel.setText("Term in Years");
		  row_b1.add(termLabel);
		  row_b1.add(termField);
		  pane.add(row_b1);

		  row_b2.setLayout(flow);
		  int_entryLabel.setText("Interest %");
		  row_b2.add(int_entryLabel);
		  row_b2.add(int_entryField);
		  pane.add(row_b2);


							  //layout for buttons to calculate, Reset, and End
							  row_c.setLayout(flow);
		  calButton.setText("Calculate");
		  calButton.setBackground(Color.green);
		  row_c.add(calButton);
		  resetButton.setText("Reset");
		  resetButton.setBackground(Color.yellow);
		  row_c.add(resetButton);
		  endButton.setText("End");
		  endButton.setBackground(Color.red);
		  row_c.add(endButton);
		  pane.add(row_c);

							  //layout for section that shows the monthly payment amount
		  row_d.setLayout(flow);
		  paymtLabel.setText("Monthly Payment Amount:");
		  row_d.add(paymtLabel);
		  row_d.add(paymtField);
		  pane.add(row_d);

							  //layout for loan amoritzation table
		  row_e.setLayout(flow);
		  outputLabel.setText("Loan Amoritization Table");
		  row_e.add(outputLabel);
		  pane.add(row_e);

		  row_f.setLayout(flowCenter);
		  opField.setLineWrap(true);
		  opField.setWrapStyleWord(true);
		  opField.setEditable(true);
		  row_f.add(scrollPane);
		  pane.add(row_f);
		}

	 


//adding actionEvents for Buttons
addActionListener(
	new ActionAdapter()
	 {
	 public void actionPerformed(ActionEvent gotevent)
	 {
		  Object source = event.getSource();
		  if (source == calButton) {
			   startCalculations();

		  }
		  if (source == resetButton) {
			   reset();

		  }
		  if (source == endButton) {
			   end();

		  }
		  if (source == opt1){

			  options.setEnabled(false);
				   termField.setEnabled(true);
			  termField.setEditable(true);
			  int_entryField.setEnabled(true);
			  int_entryField.setEditable(true);
			  }

			  if (source == opt2){

			  options.setEnabled(true);
			  termField.setEnabled(false);
			  termField.setEditable(false);
			  int_entryField.setEnabled(false);
			  int_entryField.setEditable(false);
			  }

		 }
//formulas for monthly payment
	 void startCalculations() {

		  Thread thisThread = Thread.currentThread();
		  DecimalFormat twodigits = new DecimalFormat("#,###.00");

		  double amt = 0;   //amount of loan
		  double trm = 0;   //variable for term of loan
		  double intrst = 0;  //variable for interest amount of loan
		  double moIn = 0;  //variable for monthly payment for formula
		  double moTrm = 0; //variable for monthly term for formula
		  double prin = 0;  // variable for principle
		  double paymt = 0;  //variable for payment
		  double newPrin = amt;
		  boolean Exception = false;


		  try {
			   amt = Double.parseDouble(loanField.getText());
		  } catch (DecimalFormatException e) {
			   JOptionPane.showMessageDialog(null, "Please Do Not Use Commas","Message Dialog", JOptionPane.PLAIN_MESSAGE);
			   loanField.setText(null);

		  }

		  if (opt2.isSelected())
		  {
			  if(options.getSelectedIndex() == 0)
			  {
		  trm=7;
		  intrst=5.35;
		  }
			  else if(options.getSelectedIndex() ==1)
			  {
					trm=15;
					intrst=5.5;
			  }
			  else
			  {
					trm=30;
									intrst=5.75;
							  }
							  }
							  else
							  {
		 try
					{
				   trm = Double.parseDouble(termField.getText());
					}
					catch (DecimalFormatException e)
					{
					JOptionPane.showMessageDialog(this,"Enter amounts greater than zero","Please enter new amount",JOptionPane.ERROR_MESSAGE);
					Exception=true;
					termField.setText(null);
			  }
			  try
			  {
					intrst= Double.parseDouble(int_entryField.getText());
			  }
			  catch (DecimalFormatException e)
			  {
					JOptionPane.showMessageDialog(this,"Enter amount greater than zero and with no % sign","Please enter new amount",JOptionPane.ERROR_MESSAGE);
					Exception=true;
					int_entryField.setText(null);
			  }
			}


//output for Loan Amoritzation Table
		  if (amt > 0 && trm > 0 && intrst > 0) {
			   amt = Double.parseDouble(loanField.getText());
			   moIn = (intrst / 12) / 100;
			   moTrm = trm * 12;
			   paymt = amt * (moIn / (1 - java.lang.Math.pow((1 + moIn), (-moTrm))));

			   paymtField.setText("" + Decimal.format(paymt));

			   opField.append("Payment#");
			   opField.append("			");
			   opField.append("Payment Amount");
			   opField.append("		   ");
			   opField.append("Interest");
			   opField.append("		   ");
			   opField.append("Principle Reduction");
			   opField.append("		   ");
			   opField.append("Remaining Balance");
			   opField.append("	  \n");




			   for(int i = 0; i <= moTrm; i++)
			   {
					double newIn = moIn * newPrin;
					double reduct = paymt - newIn;
					newPrin = newPrin - reduct;

				  }

					opField.append("	" + i);
					opField.append("" + Decimal.format(paymt));
					opField.append("" + Decimal.format(newIn));
					opField.append("" + Decimal.format(reduct));
					opField.append("" + Decimal.format(newPrin) + "\n");


			  }

					  if((amt <= 0 || trm <= 0 || intrst <= 0) && (Exception == false))
					  {
			   JOptionPane.showMessageDialog(null, "Please Enter Positive Numbers Only.",
						 "Message Dialog", JOptionPane.PLAIN_MESSAGE);
			   if(amt <= 0) {
				loanField.setText(null);
			}
		  }
		}

// resets GUI for another calculation
	 void reset(); {

		  loanField.setText(null);
		  paymtField.setText(null);
		  }
		 
}
//End of Program


Was This Post Helpful? 0
  • +
  • -

#13 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8342
  • View blog
  • Posts: 31,880
  • Joined: 06-March 08

Re: End of file while parsing problem

Posted 26 July 2009 - 07:43 PM

ouf... lot of job

There is not such a thing as a DecimalFormatException it is a NumberFormatException
A lot of handler who did'ny exist

OK this will compile... beside newIn and product not defined
not balanced {} have been balanced as much as I could

OK does not compile but you are in a lot better shape
I had mor than a look at it as I promise

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.DecimalFormat;
import javax.swing.JOptionPane;

//declaring content
public class MC4 extends JFrame implements ActionListener
{


	//adding initial selection options via RadioButtons
	JPanel row_aa = new JPanel();
	JRadioButton opt1 = new JRadioButton ("Manual Input", true);
	JRadioButton opt2 = new JRadioButton ("Menu Selections", false);

	//content Buttons, Panels, Labels, and TextFields

	JPanel row_a = new JPanel();
	JLabel amntLabel = new JLabel();

	JTextField loanField = new JTextField();
	JLabel loan2Label = new JLabel ();
	JPanel row_b = new JPanel();

	JPanel row_b1 = new JPanel();
	JLabel termLabel = new JLabel ();  //term
	JTextField termField = new JTextField(4);

	JPanel row_b2 = new JPanel();
	JLabel int_entryLabel = new JLabel ();  //interest
	JTextField int_entryField = new JTextField(3);

	JComboBox options = new JComboBox();
	JLabel optionsLabel = new JLabel();

	JPanel row_c = new JPanel();
	JButton calButton = new JButton();
	JButton resetButton = new JButton();
	JButton endButton = new JButton();

	JPanel row_d = new JPanel();
	JLabel paymtLabel = new JLabel();
	JTextField paymtField = new JTextField();

	JPanel row_e = new JPanel();
	JLabel outputLabel = new JLabel();

	JPanel row_f = new JPanel();
	JTextArea opField = new JTextArea(5, 55);


	JScrollPane scrollPane = new JScrollPane(opField,
			ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
			ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

	ButtonGroup radioSelect = new ButtonGroup();

	DecimalFormat Decimal = new DecimalFormat();
	String i;
	MC4() {


		//main GUI Dimensions  super("MC4- Loan Calculator with Preselected or Customized Values");
		setSize(900, 265);
		new GridLayout(6, 4, 10, 10);
		FlowLayout flowCenter = new FlowLayout(FlowLayout.CENTER);
		FlowLayout flow = new FlowLayout(FlowLayout.LEFT);

		Container pane = getContentPane();
		pane.setLayout(flow);


		setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		setVisible(true);

		//setting actionListeners for Fields and Buttons
		loanField.addActionListener(this);
		termField.addActionListener(this);
		int_entryField.addActionListener(this);
		options.addActionListener(this);
		calButton.addActionListener(this);
		resetButton.addActionListener(this);
		endButton.addActionListener(this);
		opt1.addActionListener(this);
		opt2.addActionListener(this);


		//layout for mortgage amount entry
		row_a.setLayout(flow);
		amntLabel.setText("Please Enter Loan Amount w/o Commas:");
		row_a.add(amntLabel);
		row_a.add(loanField);
		radioSelect.add(opt1);
		radioSelect.add(opt2);
		pane.add(row_a);


		//layout for options
		options.addItem("7 years at 5.35%");
		options.addItem("15 years at 5.5%");
		options.addItem("30 years at 5.75%");
		options.setEnabled(false);

		row_b.setLayout(flow);
		row_b.add(options);
		pane.add(row_b);

		row_b1.setLayout(flow);
		termLabel.setText("Term in Years");
		row_b1.add(termLabel);
		row_b1.add(termField);
		pane.add(row_b1);

		row_b2.setLayout(flow);
		int_entryLabel.setText("Interest %");
		row_b2.add(int_entryLabel);
		row_b2.add(int_entryField);
		pane.add(row_b2);


		//layout for buttons to calculate, Reset, and End
		row_c.setLayout(flow);
		calButton.setText("Calculate");
		calButton.setBackground(Color.green);
		row_c.add(calButton);
		resetButton.setText("Reset");
		resetButton.setBackground(Color.yellow);
		row_c.add(resetButton);
		endButton.setText("End");
		endButton.setBackground(Color.red);
		row_c.add(endButton);
		pane.add(row_c);

		//layout for section that shows the monthly payment amount
		row_d.setLayout(flow);
		paymtLabel.setText("Monthly Payment Amount:");
		row_d.add(paymtLabel);
		row_d.add(paymtField);
		pane.add(row_d);

		//layout for loan amoritzation table
		row_e.setLayout(flow);
		outputLabel.setText("Loan Amoritization Table");
		row_e.add(outputLabel);
		pane.add(row_e);

		row_f.setLayout(flowCenter);
		opField.setLineWrap(true);
		opField.setWrapStyleWord(true);
		opField.setEditable(true);
		row_f.add(scrollPane);
		pane.add(row_f);

		//formulas for monthly payment
	}
	void startCalculations() {

		Thread thisThread = Thread.currentThread();
		DecimalFormat twodigits = new DecimalFormat("#,###.00");

		double amt = 0;   //amount of loan
		double trm = 0;   //variable for term of loan
		double intrst = 0;  //variable for interest amount of loan
		double moIn = 0;  //variable for monthly payment for formula
		double moTrm = 0; //variable for monthly term for formula
		double prin = 0;  // variable for principle
		double paymt = 0;  //variable for payment
		double newPrin = amt;
		boolean Exception = false;


		try {
			amt = Double.parseDouble(loanField.getText());
		} catch (NumberFormatException e) {
			JOptionPane.showMessageDialog(null, "Please Do Not Use Commas","Message Dialog", JOptionPane.PLAIN_MESSAGE);
			loanField.setText(null);

		}

		if (opt2.isSelected())
		{
			if(options.getSelectedIndex() == 0)
			{
				trm=7;
				intrst=5.35;
			}
			else if(options.getSelectedIndex() ==1)
			{
				trm=15;
				intrst=5.5;
			}
			else
			{
				trm=30;
				intrst=5.75;
			}
		}
		else
		{
			try
			{
				trm = Double.parseDouble(termField.getText());
			}
			catch (NumberFormatException e)
			{
				JOptionPane.showMessageDialog(this,"Enter amounts greater than zero","Please enter new amount",JOptionPane.ERROR_MESSAGE);
				Exception=true;
				termField.setText(null);
			}
			try
			{
				intrst= Double.parseDouble(int_entryField.getText());
			}
			catch (NumberFormatException e)
			{
				JOptionPane.showMessageDialog(this,"Enter amount greater than zero and with no % sign","Please enter new amount",JOptionPane.ERROR_MESSAGE);
				Exception=true;
				int_entryField.setText(null);
			}
		}


		//output for Loan Amoritzation Table
		if (amt > 0 && trm > 0 && intrst > 0) {
			amt = Double.parseDouble(loanField.getText());
			moIn = (intrst / 12) / 100;
			moTrm = trm * 12;
			paymt = amt * (moIn / (1 - java.lang.Math.pow((1 + moIn), (-moTrm))));

			paymtField.setText("" + Decimal.format(paymt));

			opField.append("Payment#");
			opField.append("			");
			opField.append("Payment Amount");
			opField.append("		   ");
			opField.append("Interest");
			opField.append("		   ");
			opField.append("Principle Reduction");
			opField.append("		   ");
			opField.append("Remaining Balance");
			opField.append("	  \n");




			for(int i = 0; i <= moTrm; i++)
			{
				double newIn = moIn * newPrin;
				double reduct = paymt - newIn;
				newPrin = newPrin - reduct;

			}

			opField.append("	" + i);
			opField.append("" + Decimal.format(paymt));
			opField.append("" + Decimal.format(newIn));
			opField.append("" + Decimal.format(reduct));
			opField.append("" + Decimal.format(newPrin) + "\n");


		}

		if((amt <= 0 || trm <= 0 || intrst <= 0) && (Exception == false))
		{
			JOptionPane.showMessageDialog(null, "Please Enter Positive Numbers Only.",
					"Message Dialog", JOptionPane.PLAIN_MESSAGE);
			if(amt <= 0) {
				loanField.setText(null);
			}
		}
	}

	// resets GUI for another calculation
	void reset() {

		loanField.setText(null);
		paymtField.setText(null);
	}
	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		
	}

}
//End of Program




Was This Post Helpful? 0
  • +
  • -

Page 1 of 1