Results 1 to 7 of 7
  1. #1
    RBNSN is offline Member
    Join Date
    Jul 2010
    Posts
    10
    Rep Power
    0

    Default Problems with Static toString() method

    Please refer to the following screenshot.
    public class Student {

    public int StudentIdentificationNumber;
    public String FirstName;
    public String LastName;
    public int CreditsSoFar;
    public double GPA;
    @Override
    public String toString() {
    return ("FIRST Name: " + FirstName + "\n"
    + "LAST Name: " + LastName + "\n" + "Creditsofar"
    + Integer.toString(CreditsSoFar)+"\n"
    + Double.toString(GPA)+"\n");
    }

    Whenever I do this there are red lines in the code below and IDE says tht it its an "illegal start of expression". could you Please explain how I can display the numerical values of the class in the toString() method.

  2. #2
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    Post exact error messages, and we can probably help you. Until then, noone can figure out what lines you are actually having trouble with. Makes it damn hard to figure out whats wrong -.-
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,856
    Rep Power
    19

    Default

    For starters that's not a static method, so the thread title's wrong.

  4. #4
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    5

    Default

    Quote Originally Posted by RBNSN View Post
    could you Please explain how I can display the numerical values of the class in the toString() method.

    i could instantiate the Student class an call the toString() method without problems. it doesn't hurt to use the toString() method of the wrapper classes, but in println you can add it to your string directly as

    ...CreditsSoFar+"\n" + GPA+"\n");

  5. #5
    RBNSN is offline Member
    Join Date
    Jul 2010
    Posts
    10
    Rep Power
    0

    Default

    I am trying to paste a screenshot of the IDE so that I can show the error message shown in the IDE. It is simple but it is to me quite confusing.

  6. #6
    RBNSN is offline Member
    Join Date
    Jul 2010
    Posts
    10
    Rep Power
    0

    Default

    The problem is deeper than this. I will Open a new thread that will include all the problems which will be more clearer in getting picture across.

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,375
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by RBNSN View Post
    I am trying to paste a screenshot of the IDE so that I can show the error message shown in the IDE. It is simple but it is to me quite confusing.
    Can't you just manually type the error message in?

    kind regards,

    Jos

Similar Threads

  1. Replies: 4
    Last Post: 05-12-2010, 11:05 AM
  2. Replies: 3
    Last Post: 02-09-2010, 05:22 AM
  3. toString() method
    By 01allenh in forum New To Java
    Replies: 2
    Last Post: 03-25-2009, 11:43 PM
  4. Replies: 1
    Last Post: 02-10-2009, 10:03 AM
  5. Replies: 1
    Last Post: 08-07-2007, 05:05 AM

Posting Permissions

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