0% found this document useful (0 votes)
36 views

Student Roster Code

The Student class defines a student with name, graduation year, and class grades attributes. It contains constructors to initialize these attributes, a calcGPA method to calculate grade point average from class grades, and a toString method to output student information. The StudentDriver class creates a Student object and prints its details.

Uploaded by

api-315616667
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

Student Roster Code

The Student class defines a student with name, graduation year, and class grades attributes. It contains constructors to initialize these attributes, a calcGPA method to calculate grade point average from class grades, and a toString method to output student information. The StudentDriver class creates a Student object and prints its details.

Uploaded by

api-315616667
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

Student Roster Code

publicclassStudent{
privateStringname;
privateintgradYear;
privatedouble[]classGrades;

publicStudent(){
name=newString("");
gradYear=0;
classGrades=newdouble[5];
}//zeroconstructor

publicStudent(Stringname,intgradYear,doublegradeEng,doublegradeMath,
doublegradeSci,doublegradeFineArts,doublegradeHist){
this.name=name;
this.gradYear=gradYear;
this.classGrades=newdouble[5];
this.classGrades[0]=gradeEng;
this.classGrades[1]=gradeMath;
this.classGrades[2]=gradeSci;
this.classGrades[3]=gradeFineArts;
this.classGrades[4]=gradeHist;
}//endstudentconstructor
publicdoublecalcGPA(){
doubletotal=0.0;
for(intindex=0;index<classGrades.length;index++){
total+=classGrades[index];
}
total=total/classGrades.length;
returntotal;
}
publicStringtoString(){
StringstudentInfo=newString();
studentInfo="Student'snameis:"+name+"\n"+
"Stundent'sGraduationyearis:"+gradYear+"\n"+
"Student'sGPAis:"+calcGPA()+"\n";

returnstudentInfo;
}//endtoString
}//endclass

publicclassStudentDriver{
publicstaticvoidmain(String[]args){
Studentstudent1=newStudent("Stefanie",2017,4.0,4.0,4.0,4.0,4.0);

System.out.println(student1);
}//endmain
}//endclass

You might also like