
Patrick B. answered 06/23/20
Math and computer tutor/teacher
class Student
{
private String name;
private int age;
private double marksMath;
private double marksEnglish;
Student( String Name, int Age, double math, double english)
{
name = Name;
age = Age;
marksMath = math;
marksEnglish = english;
}
String GetName() { return(name); }
int GetAge() { return(age); }
double GetMathGrade() { return(marksMath); }
double GetEnglishGrade() { return(marksEnglish); }
double GetGradeAverage() { return( (marksEnglish+marksMath)/2); }
void Display ( String debugMsg)
{
System.out.println(" ****************************************************");
if (debugMsg!=null)
{
System.out.println("******************************************************");
System.out.println(debugMsg);
}
System.out.println(" name = >"+name+"<");
System.out.println(" age = " + age);
System.out.println(" math grade = "+marksMath);
System.out.println(" english grade = "+marksEnglish);
System.out.println(" grade average = " + this.GetGradeAverage() );
}
public static void main(String args[])
{
Student s = new Student("A",23,67,84);
Student s1 = new Student("B",34,45,88);
Student s2 = new Student("C",22,29,93);
Student s3 = new Student("D",17,74,38);
Student studentArray[] = new Student[4];
studentArray[0] = s;
studentArray[1] = s1;
studentArray[2] = s2;
studentArray[3] = s3;
String outbuff;
for (int iLoop=0; iLoop<4; iLoop++)
{
outbuff = "Student rec # "+ (iLoop+1);
studentArray[iLoop].Display(outbuff);
}
System.out.println("\n grades are \n");
double totalMath=0;
double totalEnglish=0;
double totalAvg = 0;
int N = studentArray.length;
System.out.println(" student math english avg ");
for (int iLoop=0; iLoop<N; iLoop++)
{
Student curStudent = studentArray[iLoop];
double math = curStudent.GetMathGrade();
double english = curStudent.GetEnglishGrade();
double avg = curStudent.GetGradeAverage();
totalMath += math;
totalEnglish += english;
totalAvg += avg;
System.out.println(" "+ curStudent.GetName() + " " + math + " " + english + " " + avg);
}
System.out.println("TOTALS: "+ totalMath + " " + totalEnglish + " " + totalAvg);
System.out.println(" AVERAGE: " + totalMath/N + " " + totalEnglish/N + " " + totalAvg/N);
}