Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / June 2007

Tip: Looking for answers? Try searching our database.

'{' expected

Thread view: 
pacvek@aol.com - 13 Jun 2007 02:09 GMT
hi everyone, I'm new to the java world and I'm need of dire help, I
have been given an assignment and for some reason I cannot compile, I
keep getting the same error and even when I add an extra bracket the
error gets greater, here is the program and hopefully someone can help
me out.

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));
}

}

}
}
}
Andrew Thompson - 13 Jun 2007 03:23 GMT
>hi everyone, I'm new to the java world ...

An inappropriate time to be taking on GUI'd applications.

>...and I'm need of dire help,

Best help for beginners is available on comp.lang.java.help

>...I
>have been given an assignment and for some reason I cannot compile, I
>keep getting the same error ...

What error?  Always copy/paste compile and runtime
error output.

>...and even when I add an extra bracket the
>error gets greater, here is the program and hopefully someone can help
[quoted text clipped - 3 lines]
>
>public class Mortgage Payment Calculator {

D:\MortgagePaymentCalculator.java:3: '{' expected
public class Mortgage Payment Calculator {
                    ^

[hint]Java class names can not contain spaces[/hint]

Signature

Andrew Thompson
http://www.athompson.info/andrew/

pacvek@aol.com - 13 Jun 2007 03:32 GMT
> pac...@aol.com wrote:
> >hi everyone, I'm new to the java world ...
[quoted text clipped - 30 lines]
>
> Message posted via JavaKB.comhttp://www.javakb.com/Uwe/Forums.aspx/java-gui/200706/1

Thanks Andrew, I closed the gaps and still this thing is making fun of
me, still getting the same error
Lew - 13 Jun 2007 03:28 GMT
> hi everyone, I'm new to the java world and I'm need of dire help, I
> have been given an assignment and for some reason I cannot compile, I
[quoted text clipped - 5 lines]
>
> public class Mortgage Payment Calculator {
...
> }
>
> }
> }
> }

You should really cite all the information, including the full, *copied* and
pasted error message, within the body of the message, rather than merely
hinting at it in the subject.  Nonetheless, it is clear what your difficulty is.

The error said '{' (left brace) expected, not right brace ('}'), so clearly
adding right braces will not help.  Adding more right braces would help even
less.  Why did you think right braces would help an error that refers to left
races?

Where would the compiler expect a left brace?  The first place is just after
the class name in the class declaration:

> public class Mortgage Payment Calculator {

but instead of a left brace, the compiler finds a token 'Payment' - whoops, a
left brace '{' expected, but not found!

You have three class names in the declaration instead of only one.  Just use one.

Signature

Lew

Lew - 13 Jun 2007 03:31 GMT
> hi everyone, I'm new to the java world and I'm need of dire help, I
> have been given an assignment and for some reason I cannot compile, I
[quoted text clipped - 5 lines]
>
> public class Mortgage Payment Calculator {
...
> }
>
[quoted text clipped - 3 lines]
> }
> }

You should really cite all the information, including the full, *copied* and
pasted error message, within the body of the message, rather than merely
hinting at it in the subject.  Nonetheless, it is clear what your difficulty is.

The error said '{' (left brace) expected, not right brace ('}'), so clearly
adding right braces will not help.  Adding more right braces would help even
less.  Why did you think right braces would help an error that refers to left
braces?

Where would the compiler expect a left brace?  The first place is just after
the class name in the class declaration:

>  public class Mortgage Payment Calculator {

but instead of a left brace, the compiler finds a token 'Payment' - whoops, a
left brace '{' expected, but not found!

You have three class names in the declaration instead of only one.  Just use one.

Signature

Lew

pacvek@aol.com - 13 Jun 2007 03:50 GMT
> pac...@aol.com wrote:
> > hi everyone, I'm new to the java world and I'm need of dire help, I
[quoted text clipped - 38 lines]
>
> - Show quoted text -

/*
MortgagePaymentCalculatorCR1.java

*/
import java.text.DecimalFormat;

public class MortgagePaymentCalculatorCR1.java:3:{

//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));
}

this is what I have done so far and the following errors are

'{' expected      line 7
'}' expected      line 55
Lew - 13 Jun 2007 03:53 GMT
> /*
> MortgagePaymentCalculatorCR1.java
[quoted text clipped - 3 lines]
>
> public class MortgagePaymentCalculatorCR1.java:3:{

This is just plain wrong.  You don't put colons or periods in class names.

What are you using to teach you the language?  Doesn't it explain what the
valid characters are for Java identifiers?

Signature

Lew

pacvek@aol.com - 13 Jun 2007 04:02 GMT
> pac...@aol.com wrote:
> > /*
[quoted text clipped - 12 lines]
> --
> Lew

I think I missed that one, I'm really not very good at this, I got rid
of the colons and periods and now I'm getting

';' expected
']' expected
<identifier> expected
']' expected
<identifier> expected
']' expected
<identifier> expected
']' expected
<identifier> expected
']' expected
<identifier> expected
']' expected
<identifier> expected
<identifier> expected
illegal start of type
<identifier> expected
<identifier> expected
<identifier> expected
<identifier> expected
<identifier> expected
Lew - 13 Jun 2007 04:07 GMT
>> pac...@aol.com wrote:
>>> /*
[quoted text clipped - 33 lines]
> <identifier> expected
> <identifier> expected

Once again, *copy* and paste the *entire* error message, along with the SSCCE
(simple, self-contained correct (compilable) example) that causes it.  We
can't keep guessing at what the trouble is with incomplete information.

Signature

Lew

pacvek@aol.com - 13 Jun 2007 04:14 GMT
On Jun 12, 8:02 pm, pac...@aol.com wrote:

> > pac...@aol.com wrote:
> > > /*
[quoted text clipped - 38 lines]
>
> - Show quoted text -

okay here it is.

F:\New Folder\MortgagePaymentCalculatorCR1.java:53: <identifier>
expected
       System.out.println("\tMonthly Payment is " +
twoplaces.format(MP));
                                 ^
20 errors

Process completed.

--------------------Configuration: <Default>--------------------
Usage: java [-options] class [args...]
          (to execute a class)
  or  java [-options] -jar jarfile [args...]
          (to execute a jar file)

where options include:
   -client   to select the "client" VM
   -server   to select the "server" VM
   -hotspot      is a synonym for the "client" VM  [deprecated]
                 The default VM is client.

   -cp <class search path of directories and zip/jar files>
   -classpath <class search path of directories and zip/jar files>
                 A ; separated list of directories, JAR archives,
                 and ZIP archives to search for class files.
   -D<name>=<value>
                 set a system property
   -verbose[:class|gc|jni]
                 enable verbose output
   -version      print product version and exit
   -showversion  print product version and continue
   -? -help      print this help message
   -X            print help on non-standard options
   -ea[:<packagename>...|:<classname>]
   -enableassertions[:<packagename>...|:<classname>]
                 enable assertions
   -da[:<packagename>...|:<classname>]
   -disableassertions[:<packagename>...|:<classname>]
                 disable assertions
   -esa | -enablesystemassertions
                 enable system assertions
   -dsa | -disablesystemassertions
                 disable system assertions

Process completed.

--------------------Configuration: <Default>--------------------
Usage: java [-options] class [args...]
          (to execute a class)
  or  java [-options] -jar jarfile [args...]
          (to execute a jar file)

where options include:
   -client   to select the "client" VM
   -server   to select the "server" VM
   -hotspot      is a synonym for the "client" VM  [deprecated]
                 The default VM is client.

   -cp <class search path of directories and zip/jar files>
   -classpath <class search path of directories and zip/jar files>
                 A ; separated list of directories, JAR archives,
                 and ZIP archives to search for class files.
   -D<name>=<value>
                 set a system property
   -verbose[:class|gc|jni]
                 enable verbose output
   -version      print product version and exit
   -showversion  print product version and continue
   -? -help      print this help message
   -X            print help on non-standard options
   -ea[:<packagename>...|:<classname>]
   -enableassertions[:<packagename>...|:<classname>]
                 enable assertions
   -da[:<packagename>...|:<classname>]
   -disableassertions[:<packagename>...|:<classname>]
                 disable assertions
   -esa | -enablesystemassertions
                 enable system assertions
   -dsa | -disablesystemassertions
                 disable system assertions

Process completed.
--------------------Configuration: <Default>--------------------
Usage: java [-options] class [args...]
          (to execute a class)
  or  java [-options] -jar jarfile [args...]
          (to execute a jar file)

where options include:
   -client   to select the "client" VM
   -server   to select the "server" VM
   -hotspot      is a synonym for the "client" VM  [deprecated]
                 The default VM is client.

   -cp <class search path of directories and zip/jar files>
   -classpath <class search path of directories and zip/jar files>
                 A ; separated list of directories, JAR archives,
                 and ZIP archives to search for class files.
   -D<name>=<value>
                 set a system property
   -verbose[:class|gc|jni]
                 enable verbose output
   -version      print product version and exit
   -showversion  print product version and continue
   -? -help      print this help message
   -X            print help on non-standard options
   -ea[:<packagename>...|:<classname>]
   -enableassertions[:<packagename>...|:<classname>]
                 enable assertions
   -da[:<packagename>...|:<classname>]
   -disableassertions[:<packagename>...|:<classname>]
                 disable assertions
   -esa | -enablesystemassertions
                 enable system assertions
   -dsa | -disablesystemassertions
                 disable system assertions

Process completed.
';' expected
']' expected
<identifier> expected
']' expected
<identifier> expected
']' expected
<identifier> expected
']' expected
<identifier> expected
']' expected
<identifier> expected
']' expected
<identifier> expected
<identifier> expected
illegal start of type
<identifier> expected
<identifier> expected
<identifier> expected
<identifier> expected
<identifier> expected
Lew - 13 Jun 2007 04:20 GMT
> okay here it is.
>
[quoted text clipped - 8 lines]
>
> --------------------Configuration: <Default>--------------------
  Meaningless garbage snipped

> Process completed.
> ';' expected
[quoted text clipped - 17 lines]
> <identifier> expected
> <identifier> expected

<http://www.physci.org/codes/sscce.html>
<http://mindprod.com/jgloss/sscce.html>

Signature

Lew

RedGrittyBrick - 13 Jun 2007 21:18 GMT
> /*
> MortgagePaymentCalculatorCR1.java
[quoted text clipped - 6 lines]
> //initialize numerical values
>     public static void main(String[] args)

snip

> '{' expected      line 7
> '}' expected      line 55

You've allowed yourself to be driven by the error messages without
really understanding them. I found it a bad idea, as a beginner, to
write 100 lines of java and then try compiling it.

Start with this - does it compile?

  /*
   * MortgagePaymentCalculator.java
   */
  public class MortgagePaymentCalculator {
      public static void main (String[] args) {
          System.out.println("Mortgage Payment Calculator");
      }
  }

A good way for a beginner to work is to not add any extra code to the
above until it compiles. Then add no more than two or three lines. Get
that to compile before proceeding. Proceed in tiny steps.

If it compiles, what do you expect as output? Try running it and see if
the actual output is as you expect. Don't add new functionality until
the existing prototype behaves exactly how you expect.

Use indentation to help you see the structure of the program.
Lew - 14 Jun 2007 00:35 GMT
> You've allowed yourself to be driven by the error messages without
> really understanding them. I found it a bad idea, as a beginner, to
[quoted text clipped - 20 lines]
>
> Use indentation to help you see the structure of the program.

What RedGrittyBrick is teaching you is also the way to put together an SSCCE.

Signature

Lew

Roedy Green - 13 Jun 2007 06:17 GMT
here is some generic advice:

1. use an IDE that formats your code. It makes bracketing errors much
easier to see.  See http://mindprod.com/jgloss/ide.html

2. look up error messages at
http://mindprod.com/jgloss/errormessages.html
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
pacvek@aol.com - 13 Jun 2007 06:55 GMT
On Jun 12, 10:17 pm, Roedy Green <see_webs...@mindprod.com.invalid>
wrote:
> here is some generic advice:
>
[quoted text clipped - 5 lines]
> Roedy Green Canadian Mind Products
> The Java Glossaryhttp://mindprod.com

thank you Roedy I will try these sites, this thing is kicking me
around I'm about to pull my own hair.
Lew - 13 Jun 2007 10:48 GMT
> thank you Roedy I will try these sites, this thing is kicking me
> around I'm about to pull my own hair.

You'll save yourself some hair if you provide SSCCEs with your questions, then
people can actually help you.

Signature

Lew

Roedy Green - 14 Jun 2007 11:13 GMT
>You'll save yourself some hair if you provide SSCCEs with your questions, then
>people can actually help you.

see http://mindprod.com/jgloss/sscce.html
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Lew - 14 Jun 2007 14:45 GMT
>> You'll save yourself some hair if you provide SSCCEs with your questions, then
>> people can actually help you.
[quoted text clipped - 4 lines]
> The Java Glossary
> http://mindprod.com

As mentioned upthread, along with the physci.org link:

<http://www.physci.org/codes/sscce.html>

-- Lew
kaldrenon - 14 Jun 2007 18:05 GMT
>                 double MP;

MP is declared here, but it never gets initialized. So when you use
it, your program will explode (not literally)

>                 double[] interestrate= new double[3];
>                 interestrate[0] =  .0535;
>                 interestrate[1] =  .0550;
>                 interestrate[2] =  .0575;

Just a small readability comment, you can have capitals in variable
names. interestRate is easier to read, no?

>                 for(int counter = 1; counter <=12; counter++);
> {
>                 //calculate

Uh oh. See that semicolon? That's breaking your code. When you do a
for loop in Java, there are two options for what follows: either a
block noted by {}, or a single line that ends with ;. What you're
doing here is telling Java "Do everything after for() but before ; 12
times," or, in your case, "Do nothing 12 times". As a result, in all
of the code you have in the {} block below, i isn't initialized, and
this code will only run once instead of 12 times, like you want.

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

PayMonthly needs to be given a type the first time it's referenced. It
looks like you've got two variables to do the same job (MP and
PayMonthly) but if you only use each half of the time, neither gets
the job done.

Side note: general coding practice (at least in Java) is to name
variables and methods with lowercase first, classes with proper case,
and constants with all upper case.

Hope that helps some. And people are right - it helps others help you
if you're clear and specific about the problem you're having. Too
little and people can't help, too much and there's garbage to sort
through to find the problem.

Good luck,
Andrew
Aziz - 14 Jun 2007 20:19 GMT
> >                 double MP;
>
[quoted text clipped - 40 lines]
> Good luck,
> Andrew

I would recommend going to your local library or book store and
getting a book on Java. Either that, or read the Java Tutorials:
http://java.sun.com/docs/books/tutorial/
JT - 15 Jun 2007 00:57 GMT
>>>                 double MP;
>> MP is declared here, but it never gets initialized. So when you use
[quoted text clipped - 40 lines]
> getting a book on Java. Either that, or read the Java Tutorials:
> http://java.sun.com/docs/books/tutorial/

Like what I'm doing right now is alternating between "The Java
Programming Language Fourth Edition" for basic stuff, and "Effective
Java" for more advanced stuff.  Both good books and both "From the Source"

Another excellent book is Head First Java, part of the Head First Series
published by O'Reilly.
pacvek@aol.com - 15 Jun 2007 03:05 GMT
> >>>                 double MP;
> >> MP is declared here, but it never gets initialized. So when you use
[quoted text clipped - 49 lines]
>
> - Show quoted text -

Thank you everyone, I really appreciate all of your help, I may not
know how to ask the right question since I'm merely a begginer.
Roedy Green - 29 Jun 2007 01:43 GMT
>Thank you everyone, I really appreciate all of your help, I may not
>know how to ask the right question since I'm merely a begginer.

so was everyone else at one point.  There is no shame in it.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.