Student Roster Code
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