'{' expected error from java programming

I keep getting this error when I compile

Page 1 of 1

10 Replies - 1473 Views - Last Post: 14 June 2007 - 06:33 PM Rate Topic: -----

#1 pacvek  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 11-June 07

'{' expected error from java programming

Posted 12 June 2007 - 06:51 PM

I keep getting an { expected error right after the public class line, any help please
import java.text.DecimalFormat;

public class Mortgage Payment Calculator

{

					  




//initialize numerical values
	public static void main(String[] args)
	
{
	
		//declared variables

		int loanamount = 200000;
		double MP;
		double Principal=200000;
				
	   
	
		int[] months= new int[3];
		months[0] = 84;
		months[1] = 180;
		months[2] = 360;
		
		//calculate
		
		double[] interestrate= new double[3];
		interestrate[0] =  .0535;
		interestrate[1] =  .0550;
		interestrate[2] =  .0575;
		DecimalFormat twoplaces = new DecimalFormat("0,000.00");

		//calculate
		System.out.println("\tMortgage Payment Calculator\n");

		//looping in progress
				for(int counter = 1; counter <=12; counter++);
{
		//calculate

	
		PayMonthly = (loantotal * interestRate[i] / (1 - Math.pow(1/(1 + interestRate[i]),loanlength[i]*12)));
{
		//calculate

		System.out.println("\tLoan Amount 1 = " + loanamount);
		System.out.println("\tYear Term is = " + yearterm[counter]);
		System.out.println("\tInterest Rate = " + interestrate[counter]*100);
		System.out.println("\tMonthly Payment is " + twoplaces.format(MP));
}
	
}	
}
	
}

}

This post has been edited by William_Wilson: 12 June 2007 - 06:56 PM


Is This A Good Question/Topic? 0
  • +

Replies To: '{' expected error from java programming

#2 William_Wilson  Icon User is offline

  • lost in compilation
  • member icon

Reputation: 205
  • View blog
  • Posts: 4,807
  • Joined: 23-December 05

Re: '{' expected error from java programming

Posted 12 June 2007 - 06:55 PM

please use [code] tags next time

the reason is your class has spaces in the names... can't do that, need to be _ or all one word
Was This Post Helpful? 0
  • +
  • -

#3 pacvek  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 11-June 07

Re: '{' expected error from java programming

Posted 12 June 2007 - 07:04 PM

thanks William, I closed the gaps on the class name and now I'm getting 'class' or 'interface' expected at the end of the program, what do you think it could be?











View PostWilliam_Wilson, on 12 Jun, 2007 - 06:55 PM, said:

please use [code] tags next time

the reason is your class has spaces in the names... can't do that, need to be _ or all one word

Was This Post Helpful? 0
  • +
  • -

#4 GWatt  Icon User is offline

  • member icon

Reputation: 278
  • View blog
  • Posts: 3,078
  • Joined: 01-December 05

Re: '{' expected error from java programming

Posted 12 June 2007 - 07:06 PM

You have one too many '}' at the end.
Was This Post Helpful? 0
  • +
  • -

#5 pacvek  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 11-June 07

Re: '{' expected error from java programming

Posted 12 June 2007 - 07:10 PM

by removing one bracket at the end I now have 13 errors, and if put one bracket back I get 'class' or 'interface' expected, i'm so lost.





View PostGWatt, on 12 Jun, 2007 - 07:06 PM, said:

You have one too many '}' at the end.

Was This Post Helpful? 0
  • +
  • -

#6 William_Wilson  Icon User is offline

  • lost in compilation
  • member icon

Reputation: 205
  • View blog
  • Posts: 4,807
  • Joined: 23-December 05

Re: '{' expected error from java programming

Posted 12 June 2007 - 07:31 PM

more errors doesn't mean what you did was wrong. compilers look for things in order if they find any errors they report them and do not move on to the next type until it is fixed.

what errors are you getting now?

The } needs to go, and the ; on the end of the for loop needs to go as well.

The set of {} around the System.out statements have no reason, they should go.

payMonthly is not defined anywhere, so it's type is unknown and thus causes an error.

Fix all of these and you'll have a good start
Was This Post Helpful? 0
  • +
  • -

#7 pacvek  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 11-June 07

Re: '{' expected error from java programming

Posted 12 June 2007 - 07:46 PM

View PostWilliam_Wilson, on 12 Jun, 2007 - 07:31 PM, said:

more errors doesn't mean what you did was wrong. compilers look for things in order if they find any errors they report them and do not move on to the next type until it is fixed.

what errors are you getting now?

The } needs to go, and the ; on the end of the for loop needs to go as well.

The set of {} around the System.out statements have no reason, they should go.

payMonthly is not defined anywhere, so it's type is unknown and thus causes an error.

Fix all of these and you'll have a good start


I got rid of the extra bracket and ; at the end of the loop now i'm getting '{' expected '}' expected
Was This Post Helpful? 0
  • +
  • -

#8 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • Joined: 11-December 06

Re: '{' expected error from java programming

Posted 12 June 2007 - 09:01 PM

OK, post the new code so that we can all see it, there are some variables that are not declared.
Was This Post Helpful? 0
  • +
  • -

#9 pacvek  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 11-June 07

Re: '{' expected error from java programming

Posted 12 June 2007 - 10:54 PM

okay, I made some changes and it got worse, I'm about to pull my own hair.

import java.text.DecimalFormat;

public class MortgagePaymentCalculatorCR1java{



//initialize numerical values
	public static void main(String[] args)
	

	
		//declared variables

		int loanamount = 200000;
		double MP;
		double Principal=200000;
				
	   
	
		int[] months= new int[3];
		months[0] = 84;
		months[1] = 180;
		months[2] = 360;
		
		//calculate
		
		double[] interestrate= new double[3];
		interestrate[0] =  .0535;
		interestrate[1] =  .0550;
		interestrate[2] =  .0575;
		DecimalFormat twoplaces = new DecimalFormat("0,000.00");

		//calculate
		System.out.println("\tPayment Calculator\n");

		//looping in progress
				for(int counter = 1; counter <=12; counter++)

		//calculate

	
		PayMonthly = (loantotal * interestRate[i] / (1 - Math.pow(1/(1 + interestRate[i]),loanlength[i]*12)));

		//calculate

		System.out.println("\tLoan Amount 1 = " + loanamount);
		System.out.println("\tYear Term is = " + yearterm[counter]);
		System.out.println("\tInterest Rate = " + interestrate[counter]*100);
		System.out.println("\tMonthly Payment is " + twoplaces.format(MP));
}









View PostPennyBoki, on 12 Jun, 2007 - 09:01 PM, said:

OK, post the new code so that we can all see it, there are some variables that are not declared.


MOD EDIT: Code Tags Added
Was This Post Helpful? 0
  • +
  • -

#10 William_Wilson  Icon User is offline

  • lost in compilation
  • member icon

Reputation: 205
  • View blog
  • Posts: 4,807
  • Joined: 23-December 05

Re: '{' expected error from java programming

Posted 13 June 2007 - 12:00 PM

View PostWilliam_Wilson, on 12 Jun, 2007 - 09:55 PM, said:

please use [code] tags next time


-please learn to use indenting, also what compiler are you using?
-when naming variables, they should not begin with capitals (only classes should begin with capitals)
- only static variables should be ALL CAPITAL letters


new problems:
1) no brackets around main method: eg missing a { after line:
public static void main(String[] args)
and missing a } at the end of the entire code.

2) PayMonthly is not defined, I assume it's a double?

3) there are no brackets {} with your for loop, thus nothing is looped.

4) loantotal is not defined, assumed it should be a double as well, accumulating payments, interest and principle? Or is this a misstype and should be loanamount?

5) you defined iterestrate, not interestRate

6) in your loop you have a variable counter, not a variable i

7) loanlength is not defined, probably an int[]

8) yearterm is not defined, again, probably int[]

9) you never assign a value to the variable MP, it will print 0 always

Fixing all of these will allow it to compile, but there are still problems, as well as runtime errors:

10) the for loop, loops 1 through 12, yet your arrays only have 3 elements, you, will receive array out of bounds errors

11) you do not use PayMonthly again after calculating, whatever it is that long formula does... why is it there?

12) i generally just don't understand where some of the array attributes come from, i believe they should be simply int/double instead.


Typos and using a wrong variable name happen from time to time, but you appear to regularly use variables which have no value or assume an array of simple variables. i think you have either copied this code in pieces from elsewhere, or you are getting ahead of yourself, before testing/compiling. As many of these issues could have been solved as you went along if after implementing a formula or variable, you test your code to ensure it still works, thus you would know the exact line the error occurred on.
Was This Post Helpful? 0
  • +
  • -

#11 pacvek  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 11-June 07

Re: '{' expected error from java programming

Posted 14 June 2007 - 06:33 PM

thanks William, this is great help, don't know how to repay you.







View PostWilliam_Wilson, on 13 Jun, 2007 - 12:00 PM, said:

View PostWilliam_Wilson, on 12 Jun, 2007 - 09:55 PM, said:

please use [code] tags next time


-please learn to use indenting, also what compiler are you using?
-when naming variables, they should not begin with capitals (only classes should begin with capitals)
- only static variables should be ALL CAPITAL letters


new problems:
1) no brackets around main method: eg missing a { after line:
public static void main(String[] args)
and missing a } at the end of the entire code.

2) PayMonthly is not defined, I assume it's a double?

3) there are no brackets {} with your for loop, thus nothing is looped.

4) loantotal is not defined, assumed it should be a double as well, accumulating payments, interest and principle? Or is this a misstype and should be loanamount?

5) you defined iterestrate, not interestRate

6) in your loop you have a variable counter, not a variable i

7) loanlength is not defined, probably an int[]

8) yearterm is not defined, again, probably int[]

9) you never assign a value to the variable MP, it will print 0 always

Fixing all of these will allow it to compile, but there are still problems, as well as runtime errors:

10) the for loop, loops 1 through 12, yet your arrays only have 3 elements, you, will receive array out of bounds errors

11) you do not use PayMonthly again after calculating, whatever it is that long formula does... why is it there?

12) i generally just don't understand where some of the array attributes come from, i believe they should be simply int/double instead.


Typos and using a wrong variable name happen from time to time, but you appear to regularly use variables which have no value or assume an array of simple variables. i think you have either copied this code in pieces from elsewhere, or you are getting ahead of yourself, before testing/compiling. As many of these issues could have been solved as you went along if after implementing a formula or variable, you test your code to ensure it still works, thus you would know the exact line the error occurred on.

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1