Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Design a class of Student that has the following attributes: • Data members: nam

ID: 3768263 • Letter: D

Question

Design a class of Student that has the following attributes: • Data members: name, Mathematics score and Chemistry score. • Function members: A default constructor of no-argument, and another constructor that accepts actual arguments. One get method that returns the name. A compAveScore() function that computes and returns the average score. average score = (Mathematics score + Chemistry score)/2.0 (2) In the main function, test the Student class as follows: • Declare an array of three elements. • Create three Student objects: a(“Bob”,60,70), b(“John”,70,80) and c(“Janet”,80,90). • Assign three objects to the array. • Loop through all objects, print out their names and average scores (call compAveScore()) such as: Bob 65 John 75 Janet 85

Explanation / Answer

import java .io.*;

class StudentMarks
{
public static void main(String[] args) {
Student[] studentArray = new Student[3];

//creation of a,b,c objects
Student a= new Student("Bob",60,70);
Student   b= new Student("Jhon",70,80);
Student   c= new Student("Janet",80,90);
studentArray[0]=a;
   studentArray[1]=b;
   studentArray[2]=c;
   for ( int i=0; i<studentArray.length; i++) {
studentArray[i].getStudentAVG();
}
}
}
class Student
{
String StudentName;
int mathematicsScore;
int chemistryScore;
double avg_Score=0;
Student(String name,int math_Score,int chem_Score)
{
StudentName=name;
mathematicsScore=math_Score;
chemistryScore=chem_Score;
}

public void compAveScore()//calculation of average of student
{
avg_Score=(mathematicsScore+chemistryScore)/2.0;
}
public void getStudentAVG()//get student name and average score
{
compAveScore();
System.out.println(StudentName+" "+avg_Score);
}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote