S
SpeedRunner
Guest
Having trouble with the subclass in this program...
It's giving me these errors:
Clearly I am making a mistake, as I'm having the same error 6 different times. What does that error mean?
Code:
/**
This simply provides a driver to exercise the exciting
Student class.
@see Student
*/
public class StuList2
{
/**
Should not instantiate!
*/
private StuList2(){};
public static void main(String[] args)
{
Student[] stus = new Student[8];
stus[0] = new Student(123,"Fred",3.4);
stus[1] = new Student(234,"Suzy");
stus[2] = new Student(345,4.0);
stus[3] = new Student(456);
stus[4] = new GradStudent(567,"Tom",3.6,"Computers");
stus[5] = new GradStudent(678);
stus[6] = new GradStudent(789,"Ned",3.3);
stus[7] = new GradStudent(891,"Betty");
stus[4].setGPA(3.9);
stus[4].setName("Thomas");
for(int i=0; i<stus.length; i++)
{
System.out.println(stus[i]);
System.out.println(stus[i].getName() + " has number " + stus[i].getNumber() + "\n");
}
}
}
// Student class encapsulates a student's name, number, and gpa.
class Student
{
// creates variables for student class
private int number;
private String name;
private double GPA;
// constructs a new student, given a name, number and gpa.
public Student(int n, String m, double g)
{
number = n;
name = m;
GPA = g;
}
public Student(int number, double GPA)
{
this(number, "Student " + number, GPA);
}
public Student(int number)
{
this(number, "Betty", 0.0);
}
public Student(int number, String name)
{
this(number, name, 0.0);
}
public String getName()
{
return name;
}
public int getNumber()
{
return number;
}
public double setGPA(double g)
{
GPA = g;
return GPA;
}
public String setName(String m)
{
name = m;
return name;
}
public String toString()
{
return (name + ", " + number + ", " + GPA);
}
}
class GradStudent extends Student
{
// creates thesis variable
private String thesis;
private int number;
private String name;
private double GPA;
public GradStudent(int n, String m, double g, String t)
{
super(n, m, g);
thesis = t;
GPA = g;
name = m;
number = n;
}
public GradStudent()
{
this(number, name, GPA, thesis);
}
public GradStudent(int number)
{
this(number, "GradStudent " + name, 0.0, "Undecided");
}
public GradStudent(int number, String name, double g)
{
this(number, name, GPA, "Undecided");
}
public GradStudent(int number, String name)
{
this(number, name, "0.0", "Undecided");
}
}
It's giving me these errors:
Code:
C:\Documents and Settings\Marshall\My Documents\JAVA\StuList2.java:114: cannot reference number before supertype constructor has been called
this(number, name, GPA, thesis);
^
C:\Documents and Settings\Marshall\My Documents\JAVA\StuList2.java:114: cannot reference name before supertype constructor has been called
this(number, name, GPA, thesis);
^
C:\Documents and Settings\Marshall\My Documents\JAVA\StuList2.java:114: cannot reference GPA before supertype constructor has been called
this(number, name, GPA, thesis);
^
C:\Documents and Settings\Marshall\My Documents\JAVA\StuList2.java:114: cannot reference thesis before supertype constructor has been called
this(number, name, GPA, thesis);
^
C:\Documents and Settings\Marshall\My Documents\JAVA\StuList2.java:119: cannot reference name before supertype constructor has been called
this(number, "GradStudent " + name, 0.0, "Undecided");
^
C:\Documents and Settings\Marshall\My Documents\JAVA\StuList2.java:124: cannot reference GPA before supertype constructor has been called
this(number, name, GPA, "Undecided");
^
C:\Documents and Settings\Marshall\My Documents\JAVA\StuList2.java:129: cannot find symbol
symbol : constructor GradStudent(int,java.lang.String,java.lang.String,java.lang.String)
location: class GradStudent
this(number, name, "0.0", "Undecided");
^
7 errors
Tool completed with exit code 1
Clearly I am making a mistake, as I'm having the same error 6 different times. What does that error mean?