I'm working on a project that i can't seem to get done. when i try to write my constructors the compiler tells me it can't find the symbol. any idea why? here's the code.

public class Student 
 {
    String name= "XXX XXXX";
    String studentid="XXXXXXXX";
    String major="XXXX";
    String studenttype="Invalid student type";
    int numberofhourscompleted=0;
    int currenthoursenrolled= 0;
    int completedhours=0;
    String classification;

    public Student(String nam, String sid, String sMajor, String sType, int hoursCompleted, int hoursEnrolled, int completedHours, String type)
    {
        name= nam;
        studentid=sid;
        major=sMajor;
        studenttype=sType;
        numberofhourscompleted=hoursCompleted;
        currenthoursenrolled=hoursEnrolled;
        completedhours=completedHours;
        classification=type;
    }  
       Student student1 = new Student();
     {
     }
       Student student2  = new Student();
     {

     }
     public void setName(String name)
     {
     }
      public String getName()
     { 
      return name;
     }
     public void setStudentId(String studentid)
     {
     }

     public String getStudentId()
     {
      return studentid;
     }
     public void setMajor(String major)
     {
     }
     public String getMajor()
     {
       String major="XXXX";

       if (major=="CSCI")
           major="CSCI";
       else if (major=="MATH")
           major="MATH";
       else if (major=="NURS")
           major="NURS";
       else              //invalid type
           major="XXXX";

       return major;
     }
     public void setNumberOfHoursCompleted(int numberofhourscompleted)
     {
     }
     public int getNumberOfHoursCompleted()
     {
      return numberofhourscompleted;
     }
     public void setCurrentHoursEnrolled(int currenthoursenrolled)
     {
     }
     public int getCurrentHoursEnrolled()
     {
      int currenthoursenrolled=0;
      return currenthoursenrolled;
     }
     public void addCompletedHours()
     {
       int completedhours;

       completedhours=numberofhourscompleted + currenthoursenrolled;

     }
      public void setStudentType(String studenttype)
     {
     }
     public String getStudentType()
     {
       String studenttype= "X";

       if (studenttype=="U")
           studenttype="Undergraduate";
       else if (studenttype=="G")
           studenttype="Graduate Student";
       else
           studenttype="Invalid student type";

        return studenttype;
      }
      public void setClassification(String classification)
      {
      }
      public String getClassification()
      {
        String classification;
        if (completedhours<30)
            classification="Freshman";
        else if (completedhours>30)
            classification="Sophomore";
        else if (completedhours>60)
            classification="Junior";
        else if (completedhours>90)
            classification="Senior";
        else if (studenttype=="G")
            classification="Graduate Student";
        else
            classification="Invalid student type";

        return classification;
      }

     public String getStudentRecord(String studentrecord)
      {


          studentrecord=("********** creating student with " + name + "constructor **********")
                       +("Student information for" + name)
                       +("-----------------------------")
                       +("Id: " + getStudentId())
                       +("Major: " + getMajor())
                       +("Classification: " + getStudentType())
                       +("Current Hours: " + getCurrentHoursEnrolled())
                       +("Completed Hours: " + getNumberOfHoursCompleted())
                       +("Classification: " + getClassification());

         return studentrecord;
      }





 }

it's not totally done. i just can't figure out the error.

Edited 3 Years Ago by mike_2000_17: Fixed formatting

I assume it's these lines that are causing the problem?

...
Student student1 = new Student();
...
Student student2 = new Student();
...

Well, that would be because they are attempting to use the default constructor, and your class doesn't have one. The compiler will automatically create a default constructor for your class, only if you haven't defined any constructors. As soon as you define a constructor, the compiler will no longer create the default constructor.

So, if you want to be able to call a constructor with no arguments, you will need to define a constructor with no arguments (or delete all other constructors, which would probably be counter-productive).

This article has been dead for over six months. Start a new discussion instead.