Results 1 to 9 of 9
Like Tree2Likes
  • 2 Post By Fubarable

Thread: <identifier> expected

  1. #1
    Keke101 is offline Member
    Join Date
    Jan 2012
    Posts
    8
    Rep Power
    0

    Default <identifier> expected

    Hi all I am taking an intro to programming (Java) class and I am working on an assignment and I keep getting this error. Here is my code and the error I am getting.

    Java Code:
    // Class Phone represents a telephone object
    public class Phone 
    {
      private static String firstname; 
      private static String lastname;
      private static String number;
    
      public Phone()
     {
    }
    
      public Phone(String firstname1, String lastname1, String number1)
       {
       firstname = first1;
       lastname = last1;
       number = number1;
       }
    
    public static String getfirstname()
     {
      return firstname;
     }
    public void setfirstname(String first1);
     {
      firstname = first1;
     }
    public static string getlastname()
     { 
      return lastname;
     }
    public void setlastname(String last1);
     {
      lastname = last1;
     }
    public static String getnumber()
     {
      return number;
     }
    public void setnumber(String number1);
     {
      number = number1;
     }
     System.out.println("First Name : " + getfirstname()); [error here]
     System.out.println("Last Name : " + getlastname()); [error here]
     System.out.println("Number : " + getnumber()); [error here]
     }
    }
    File: C:\Documents and Settings\Keke\Desktop\School\Programming\Lab03\Les son3_5\src\Phone.java [line: 43]
    Error: C:\Documents and Settings\Keke\Desktop\School\Programming\Lab03\Les son3_5\src\Phone.java:43: <identifier> expected

    Thank you in advance to anyone who can help. I would greatly appreciate it.
    Last edited by Keke101; 01-02-2012 at 04:07 AM. Reason: code tags added

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: <identifier> expected

    You need to format your code better with consistent and proper indentation, not so it will look pretty (that's just an added bonus), but doing this will help you see where you've got mis-matched code braces and code outside of methods that can't be called outside of methods.

    Welcome to the java-forums by the way.

  3. #3
    Keke101 is offline Member
    Join Date
    Jan 2012
    Posts
    8
    Rep Power
    0

    Default Re: <identifier> expected

    Thank you for the feedback Fubarable. Could you please give me some tips on the proper indentation that you are referring to? I am looking at this and I am still not quite getting it.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: <identifier> expected

    Quote Originally Posted by Keke101 View Post
    Thank you for the feedback Fubarable. Could you please give me some tips on the proper indentation that you are referring to? I am looking at this and I am still not quite getting it.
    Often it's best to look at the code in your text books or tutorials and see how they line up the lines, the curly braces, how blocks are indented a regular amount (usually 3 spaces), and how each opening curly brace { matches a closing curly brace }.

    So count your opening braces and your closing braces -- do they match?
    So check to see if the code that's causing the error is inside of a method or constructor as it's supposed, or is it hanging in the breeze?

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: <identifier> expected

    OK, I've been going through your code and I hate to say it but it's chock full of errors suggesting that you're going about coding wrong and will want to discard this code and start again. The problem is you're not compiling, checking for errors, and correcting often enough and early enough, but instead you're typing in all your code first and only when done are you checking for errors, and this technique will only lead to a rat's nest full of errors and misery because you end up adding code to already bad code.

    Instead, if you're not using an IDE, compile very early and very often, say after adding each line or two of code, and then if there are any compiler errors don't add any more new code until you've fixed the code you've got. Again, if you don't do this you end up adding new code to already bad code.
    pbrockway2 and ankiit like this.

  6. #6
    Keke101 is offline Member
    Join Date
    Jan 2012
    Posts
    8
    Rep Power
    0

    Default Re: <identifier> expected

    Thank again soooo much that was very helpful. I think now as long as I can write the driver to test this I will be doing great.

  7. #7
    Keke101 is offline Member
    Join Date
    Jan 2012
    Posts
    8
    Rep Power
    0

    Default Re: <identifier> expected

    Okay so my driver test is not coming along well at all.......any ideas

    public static void main(String[] args)
    {
    Phone number;
    number = getnumber();
    System.out.println("First Name: " = getfirstname() + "Last Name: " = getlastname()
    + "Number: " = getnumber());

    or am I just going about this entirely wrong?

  8. #8
    ankiit is offline Member
    Join Date
    Dec 2011
    Location
    India
    Posts
    74
    Rep Power
    0

    Default Re: <identifier> expected

    Hi keke101,

    Can you please share the "intro to programming class" tutorial and the assignments that you are working upon.

    Thanks in Advance
    Ankit

  9. #9
    karthiga is offline Member
    Join Date
    Jan 2012
    Posts
    2
    Rep Power
    0

    Default Re: <identifier> expected

    Just u drop down last one brace...

Similar Threads

  1. <identifier expected> error. please help!
    By christopherx in forum AWT / Swing
    Replies: 9
    Last Post: 10-02-2011, 10:23 PM
  2. Identifier expected
    By jr2648 in forum AWT / Swing
    Replies: 2
    Last Post: 11-16-2010, 04:59 PM
  3. <identifier> expected
    By SwEeTAcTioN in forum New To Java
    Replies: 7
    Last Post: 12-05-2009, 05:05 AM
  4. identifier expected
    By tlouvierre in forum New To Java
    Replies: 4
    Last Post: 05-28-2009, 12:11 AM
  5. Identifier expected error
    By vasu18 in forum New To Java
    Replies: 1
    Last Post: 01-01-2008, 05:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •