A Teacher has five students who have taken four test. the teacher uses a grading
ID: 3620340 • Letter: A
Question
A Teacher has five students who have taken four test. the teacher uses a grading scale to assign a letter grade. 90-100 A, 80-89 B, etc... to F.Write a clas that uses a string Array or an ArrayList object to hold the five students names, an array of five characters to hold the five letter grades, and five arrays of four doubles each tohold each student'sset of test scores. The class should have methods that return a specific student's name, averagetest score, and a letter grade basedon the average.
Demonstrate the class in a program that allows teh user to enter each student's name and his or her four test scores. I should then display each students average test score and letter grade.
do not except test scoress less tghan zero or greater than 100.
Explanation / Answer
please rate - thanks hope this is good. If not message meimport java.util.*;
public class main
{
public static void main(String[] args)
{Scanner in=new Scanner(System.in);
String []name=new String[5];
char []grade=new char [5];
double[][]scores=new double[5][4];
double []average=new double[5];
int i,j;
for(i=0;i<5;i++)
{System.out.print("Enter student "+ (i+1)+"s name:");
name[i]=in.nextLine();
System.out.println("Enter grades for "+name[i]);
for(j=0;j<4;j++)
{System.out.print("Enter grade "+(j+1)+": ");
scores[i][j]=in.nextDouble();
while(scores[i][j]<0||scores[i][j]>100)
{System.out.println("must be between 0 and 100");
System.out.print("Enter grade "+(j+1)+": ");
scores[i][j]=in.nextDouble();
}
}
in.nextLine();
}
System.out.println("Name Average Grade");
for(i=0;i<5;i++)
{average[i]=getaverage(i,scores);
grade[i]=getgrade(average[i]);
}
for(i=0;i<5;i++)
System.out.println(getname(i,name)+" "+average[i]+" "+grade[i]);
}
public static char getgrade(double average)
{if(average>=90)
return 'A';
else if(average>=80)
return 'B';
else if(average>=70)
return 'C';
else if(average>=60)
return 'D';
else
return 'F';
}
public static double getaverage(int i,double s[][])
{int j;
double sum=0;
for(j=0;j<4;j++)
sum+=s[i][j];
return sum/4.;
}
public static String getname(int i,String n[])
{return n[i];
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.