Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2012
    Posts
    9
    Rep Power
    0

    Default Error: Cannot find symbol defined? Please help quickly.

    It says the variables I put in bold are not defined... but I defined them in the previous constructor. I don't understand, and this is due tonight, so if anyone can help I'd really appreciate it!


    import java.util.Calendar;
    public class StudentTC
    {
    private String name;
    private int test1;
    private int test2;
    private int test3;
    private int age;

    public StudentTC()
    {
    name = "";
    test1 = 0;
    test2 = 0;
    test3 = 0;
    age = 0;
    }

    public StudentTC(String nm, int t1, int t2, int t3, int a)
    {
    name = nm;
    test1 = t1;
    test2 = t2;
    test3 = t3;
    age = a;
    }

    public StudentTC(StudentTC s)
    {
    name = s.name;
    test1 = s.test1;
    test2 = s.test2;
    test3 = s.test3;
    age = s.age;
    }

    public class AlumniTC extends StudentTC
    {
    Calendar now = Calendar.getInstance();
    private int gMonth;
    private int gDay;
    private int gYear;

    public AlumniTC()
    {
    super();
    gMonth = 0;
    gDay = 0;
    gYear = 0;
    }

    public AlumniTC(String nm, int t1, int t2, int t3, int a, int m, int d, int y)
    {
    super(nm, t1, t2, t3, a);
    gMonth = m;
    gDay = d;
    gYear = y;
    }
    public AlumniTC(AlumniTC a)
    {
    super(a);
    gMonth = a.gMonth;
    gDay = a.gDay;
    gYear = a.gYear;
    }


    public void setGradMonth(int gMonth)
    {
    gMonth = m;
    }

    public int getGradMonth()
    {
    return gMonth;
    }

    public void setGradDay(int day)
    {
    gDay = d;
    }

    public int getGradDay()
    {
    return gDay;
    }

    public void setGradYear(int year)
    {
    gYear = y;
    }

    public int getGradYear()
    {
    return gYear;
    }

    public int getReunionDate()
    {
    int reunionYear;
    if(gYear + 10 < now.get(Calendar.YEAR))
    reunionYear = -1;
    else
    reunionYear = gYear + 10;
    return reunionYear;
    }
    }

    public void setName(String nm)
    {
    name = nm;
    }

    public String getName()
    {
    return name;
    }

    public void setScore(int i, int score)
    {
    if (i == 1)
    test1 = score;
    else if (i == 2)
    test2 = score;
    else
    test3 = score;
    }

    public int getScore(int i)
    {
    if (i == 1)
    return test1;
    else if (i ==2)
    return test2;
    else
    return test3;
    }

    public int getAverage()
    {
    int average;
    average = (int) Math.round((test1 + test2 + test3) / 3.0);
    return average;
    }

    public void setAge(int a)
    {
    age = a;
    }

    public int getAge()
    {
    return age;
    }

    public int getHighScore()
    {
    int highScore;
    highScore = test1;
    if (test2 > highScore)
    highScore = test2;
    if (test3 > highScore)
    highScore = test3;
    return highScore;
    }
    public String toString()
    {
    String str;
    str = "Name: " + name + "\nAge: " + age + "\nTest 1: " + test1 + "\nTest 2: " + test2 + "\nTest 3: " + test3 + "\nAverage: " + getAverage() + "\nStatus: " + getHonorsStatus() + "Graduation Date: " + getGradMonth() + "/" + getGradDay() + "/" + getGradYear() + "\nReunion Year: " + getReunionDate();
    return str;
    }

    public String getHonorsStatus()
    {
    int average = getAverage();
    String status;
    if(average > 90)
    status = "Honors";
    else if(average > 80)
    status = "Almost Honors";
    else if(average > 70)
    status = "Needs work";
    else
    status = "No status";
    return status;
    }
    }

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    12,999
    Blog Entries
    7
    Rep Power
    19

    Default Re: Error: Cannot find symbol defined? Please help quickly.

    Quote Originally Posted by compscistudent1 View Post
    public void setGradMonth(int gMonth)
    {
    gMonth = m;
    }
    What is 'm'? And why do you want to change the parameter 'gMonth'? Maybe your intention was:

    Java Code:
    public void setGradMonth(int m) {
       gMonth = m;
    }
    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Join Date
    Nov 2012
    Posts
    9
    Rep Power
    0

    Default Re: Error: Cannot find symbol defined? Please help quickly.

    Thanks a lot! However... I still have one problem. When I try to test it (in a working, separate, driver class) using:

    AlumniTC a1 = new AlumniTC("Theo", 70, 80, 90, 17, 5, 9, 1995);

    it gives me the same error, error: cannot find symbol, about both uses of AlumniTC. Any remedy for this one?
    Thanks so much again.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    12,999
    Blog Entries
    7
    Rep Power
    19

    Default Re: Error: Cannot find symbol defined? Please help quickly.

    Your AlumniTC class is an inner class for the StudentTC class; if that's not what you wanted, check your curly brackets.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Error: Cannot find symbol
    By surendra0607 in forum New To Java
    Replies: 3
    Last Post: 02-05-2012, 08:13 PM
  2. Replies: 7
    Last Post: 10-25-2011, 04:47 AM
  3. error: Cannot find symbol
    By iswan in forum AWT / Swing
    Replies: 3
    Last Post: 09-30-2011, 04:02 PM
  4. Replies: 9
    Last Post: 10-18-2008, 08:26 PM
  5. Error: cannot find symbol
    By silvia in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 05:39 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
  •