Results 1 to 3 of 3

Thread: Very confusing...

  1. #1
    Join Date
    Jan 2007
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Very confusing...

    Ok i am working on this program that deals with inheritance. I start out with a Student parent class then i am going to have a college, middle school, and high school children.

    Currently i have got the middle school and almost have the high school. the middle school seems to be working fine but the high school is not even though they seem to be the same.

    Here is my high school class
    Code:
    class HighSchool extends Student
       {
          int gradYear2, credLeft, SAT, apCred;
           public HighSchool(String name, int age, String schoolName, int id, double gpa, int graduationYear, int creditLeft, int sat, int apCredit);
          {
          	super(name, age, id, schoolName, gpa);
          	gradYear2 = graduationYear;
          	credLeft = creditLeft;
          	SAT = sat;
          	apCred = apCredit;
          }
       
           public String toString()
          {
          	String temp = super.toString();
             return temp + "Graduation Year: " +gradYear+ "\nCredits Left: "+credLeft+"\nSAT Score: "+SAT+"\nAP Credits Taken: "+apCred;
          }
       
       }
    and here is my middle school

    Code:
        class MiddleSchool extends Student
       {
          int gradYear1;
       
           public MiddleSchool(String name, int age, String schoolName, int id, double gpa, int gradYear)
          {
             super(name, age, id, schoolName, gpa);
             gradYear1 = gradYear;
          }
       
           public String toString()
          {	
             String temp = super.toString();
             return temp + gradYear1;
          }
       }
    the errors i am getting are :
    HighSchool.java:4: missing method body, or declare abstract
    public HighSchool(String name, int age, String schoolName, int id, double gpa, int graduationYear, int creditLeft, int sat, int apCredit);
    ^
    HighSchool.java:6: call to super must be first statement in constructor
    super(name, age, id, schoolName, gpa);
    ^
    HighSchool.java:7: cannot find symbol
    symbol : variable graduationYear
    location: class HighSchool
    gradYear2 = graduationYear;


    any suggestions?

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    All caused by the extra semicolon here:
    Code:
           public HighSchool(String name, int age, String schoolName, int id, double gpa, int graduationYear, int creditLeft, int sat, int apCredit);
    Java convention (and common sense) would have you call them "HighSchoolStudent" and "MiddleSchoolStudent."
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Jan 2007
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    AHHH i knew it was somethign like that. i had looked at it like 10 times and didnt notice that...

    thanks again!

Bookmarks

Posting Permissions

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