Help Please Write a program called StudentAverageTestScoreja
Help Please!!
Write a program called StudentAverageTestScore.java. Five students have taken five tests. The program should ask the user to enter each student\'s name and his or her five test scores. The five student names should be stored in an array, and the five test scores for each student should also be stored in an array. Use nested loops, in which the outer loop handles the student names, and the inner loop handles the current student\'s test scores. This program should have methods that return a specific student\'s name, average test score, and a letter grade based on the average. Write the following methods in the program. Print a project description that tells the user what to do. calAvg- This method should accept five test scores as an argument and return the average of the test scores. letterGrade - This method should accept test scores as an argument and return a letter grade for the test scores, based on the following grading scale. getName - This method should accept student names as an argument and return a student\'s name. Score Letter Grade 90-100 A 80-89 B 70-79 C 60-69 D Below 60 F The program should display each student\'s average test score (formatted to one decimal place) and letter grade. **lnput validation: Do not accept test scores less than zero or greater than 100. *Note: Comment your program Use meaningful prompts Provide clear instructions to the userSolution
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package StudentAverageTestScore;
import java.util.Scanner;
public class StudentAverageTestScore {
//Get the name from the user and return it
public static String getName()
{
Scanner input = new Scanner(System.in);
return input.next();
}
//Calculate the average based on the scores array and return it
public static double calcAvg(double[] scores)
{
double sum = 0;
for(int i=0;i<scores.length;i++)
sum = sum+scores[i];
return sum/scores.length;
}
//Compute the letter grade and returns it
public static char letterGrade(double score)
{
if(score>=90)
return \'A\';
else if(score>=80)
return \'B\';
else if(score>=70)
return \'C\';
else if(score>=60)
return \'D\';
else
return \'F\';
}
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
String[] studentNames = new String[5];
double[] scores = new double[5];
double[] studentAverage = new double[5];
char[] grades = new char[5];
for(int i=0;i<5;i++)
{
System.out.print(\"Enter the name of the student \" + (i+1) + \" : \");
studentNames[i] = getName();
for(int j=0;j<5;j++)
{
System.out.print(\"Enter the score for test \" + (j+1) + \" : \");
scores[j] = input.nextDouble();
while(scores[j]<0 || scores[j]>100)
{
System.out.print(\"Please enter a valid score : \");
scores[j] = input.nextDouble();
}
}
studentAverage[i] = calcAvg(scores);
grades[i] = letterGrade(studentAverage[i]);
}
System.out.println(\"Name\\tAverage\\tGrade\");
for(int i=0;i<5;i++)
System.out.printf(\"%s\\t%.1f\\t%c\ \", studentNames[i],studentAverage[i],grades[i]);
}
}
OUTPUT:
run:
Enter the name of the student 1 : John
Enter the score for test 1 : 40
Enter the score for test 2 : 50
Enter the score for test 3 : 60
Enter the score for test 4 : 70
Enter the score for test 5 : 80
Enter the name of the student 2 : David
Enter the score for test 1 : 60
Enter the score for test 2 : 60
Enter the score for test 3 : 60
Enter the score for test 4 : 900
Please enter a valid score : 60
Enter the score for test 5 : 60
Enter the name of the student 3 : Wayne
Enter the score for test 1 : 70
Enter the score for test 2 : 70
Enter the score for test 3 : 70
Enter the score for test 4 : 70
Enter the score for test 5 : 70
Enter the name of the student 4 : Alex
Enter the score for test 1 : 56
Enter the score for test 2 : 67
Enter the score for test 3 : 78
Enter the score for test 4 : 89
Enter the score for test 5 : 90
Enter the name of the student 5 : Frank
Enter the score for test 1 : 55
Enter the score for test 2 : 65
Enter the score for test 3 : 76
Enter the score for test 4 : 87
Enter the score for test 5 : 98
Name Average Grade
John 60.0 D
David 60.0 D
Wayne 70.0 C
Alex 76.0 C
Frank 76.2 C
BUILD SUCCESSFUL (total time: 49 seconds)


