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

write the definition of the class Tests such that an object of this class can st

ID: 3788384 • Letter: W

Question

write the definition of the class Tests such that an object of this class can store a student's 1st name, last name, 5 test scores, average tests score, and grade. (use array to store test scores). Add constructors and methods to manipulate data stored in an object. Among other things, your class must contain methods to calculate grades, and modify, individualing test scores. The method toString must return test data (including student's name, 5 test scores, average, and grade) as a string.

this is from the Java programming from prolem analysis to program design BY: D.S. Malik

So im trying to get this in JAVA code Please.

thank you so much for anything

Explanation / Answer


public class Test {
   String fname,lname;
   int scores[];
   float avg;
   String grade;
  
   Test(String f,String l,int s[])
   {
       fname=f;
       lname=l;
       scores=s;
       avg=0;
   }
float getAverage()
{
   for(int i=0;i<scores.length;i++)
   {
       avg+=scores[i];
   }
   return (avg/scores.length);
}

String getGrades(float a)
{
  
  
   if(a>90)
       grade="A";
   else if(a>80 &&a<90)
       grade="B";
   else
       grade="C";
   return grade;
  
}
   public static void main(String[] args) {
       // TODO Auto-generated method stub
       int sco[]={40,50,60,70,80};
       Test t=new Test("Akshay","Abhnag",sco);
       float a=t.getAverage();
       System.out.println("Average is "+a);
       System.out.println("Grade is "+t.getGrades(a));


   }

}

=============================================================

Average is 60.0
Grade is C