posted 21 years ago
Thanks I get what you are saying about that. Now my problem is implementing it in StudentTest. Here are my errors
StudentTest.java:42: cannot resolve symbol
symbol : method insertStudent ()
location: class StudentRecord
stud.insertStudent();
^
StudentTest.java:43: cannot resolve symbol
symbol : method insertStudent ()
location: class StudentRecord
stud1.insertStudent();
^
StudentTest.java:44: cannot resolve symbol
symbol : method insertStudent ()
location: class StudentRecord
stud2.insertStudent();
^
StudentTest.java:47: cannot resolve symbol
symbol : variable sort
location: class StudentTest
sort.table();
^
StudentTest.java:49: cannot resolve symbol
symbol : variable table
location: class StudentTest
table.print();
^
I know it has something to do with the methods that I have created, I just don't know what.
My code again
Gradebook
/**
*
*
*
*
*/
public class StudentRecord
{
final int arraySize = 25;
// Private instance varibles
private final String name; // student name
private final int[] grades; // grades
int Count; // number of grades per student
// Constructor
StudentRecord(String studentName, int[] grades1) {
if (grades1.length > arraySize)
{
throw new IllegalArgumentException("Grade array exceeds fixed size");
}
name = studentName ;
grades = new int[arraySize];
System.arraycopy(grades1, 0, grades, 0, grades1.length);
Count = grades1.length ;
} StudentRecord(String studentName)
{
//Call the two arg constructor with an empty grade array
this(studentName, new int[0]); }
public int compareTo(Object obj)
{
return this.name.compareTo(((StudentRecord) obj).name);
}
public void print ()
{
System.out.println ( "Name: " + name );
System.out.println( "Grades:");
for ( int j=0; j < Count ; j++ )
System.out.println ( " grade " + j + ": " + grades[ j ] );
}
public void addGrade ( int grade )
{
if ( Count < arraySize )
grades[Count] = grade ;
Count ++ ;
}
public int average ( )
{
int sum = 0 ;
for ( int j=0; j < Count; j++ )
sum += grades[ j ] ;
return sum / Count ;
}
}
Student Test
[CODE]
class StudentTest
{
public static void main ( String[] args )
{
// create a student object
StudentRecord stud = new StudentRecord( "Nate" ) ;
// add a few grades
stud.addGrade( 90 ) ;
stud.addGrade( 95 ) ;
stud.addGrade( 88 ) ;
stud.addGrade( 78 ) ;
stud.addGrade( 82 ) ;
stud.addGrade( 97 ) ;
StudentRecord stud1 = new StudentRecord( "Yvette" ) ;
// add a few grades
stud1.addGrade( 90 ) ;
stud1.addGrade( 95 ) ;
stud1.addGrade( 88 ) ;
stud1.addGrade( 78 ) ;
stud1.addGrade( 82 ) ;
stud1.addGrade( 97 ) ;
StudentRecord stud2 = new StudentRecord( "Maria" ) ;
// add a few grades
stud2.addGrade( 90 ) ;
stud2.addGrade( 95 ) ;
stud2.addGrade( 88 ) ;
stud2.addGrade( 78 ) ;
stud2.addGrade( 82 ) ;
stud2.addGrade( 97 ) ;
stud.print() ;
stud1.print() ;
stud2.print() ;
stud.insertStudent();
stud1.insertStudent();
stud2.insertStudent();
sort.table();
table.print();
System.out.println( "Average grade: " + stud.average() );
}
}
How can I print this alphabetically after they are averaged?
[CODE]