Grade Book (Java Programming Main Method - One Class) A teacher has five student
ID: 3704075 • Letter: G
Question
Grade Book (Java Programming Main Method - One Class)
A teacher has five students who have taken four tests. The teacher uses the following grading scale to assign a letter grade to a student, based on the average of his or her four test scores:
Test Score Letter Grade
90 – 100 A
80 – 89 B
70 – 79 C
60 – 69 D
0 – 59 F
Write a class that uses a String array (or an ArrayList object) to hold the five student’s names, an array of the five characters to hold the five student’s letter grades, and five arrays of four doubles each to hold each student’s set of test scores. The class should have methods that return a specific student’s name, average test score, and a letter grade based on the average.
Demonstrate the class in a program that allows the user to enter each student’s name and his or her four test scores. It should then display each student’s average test score and letter grade.
Input Validation: Do not accept test scores less than zero or greater than 100.
Explanation / Answer
Please find my implementation.
Please let me know in case of any issue.
import java.util.Scanner;
class Gradecalculator
{
static String [] names=new String[5];
static char [] grades=new char[5];
static double [][] testscore=new double[5][4];
protected char[] calculate(double [][] testscore)
{
double total[]=new double[5];
for(int i=0;i<5;i++)
{
for(int j=0;j<4;j++)
{
total[i]=0;
}
}
for(int i=0;i<5;i++)
{
for(int j=0;j<4;j++)
{
total[i]=total[i]+testscore[i][j];
}
}
for(int i=0;i<5;i++)
{
total[i]=total[i]/4;
}
for(int i=0;i<5;i++)
{
if(total[i]>=90&&total[i]<=100)
grades[i]='A';
else if(total[i]>=80&&total[i]<90)
grades[i]='B';
else if(total[i]>=70&&total[i]<80)
grades[i]='C';
else if(total[i]>=60&&total[i]<70)
grades[i]='D';
else
grades[i]='F';
}
return(grades);
}
}
public class Grade extends Gradecalculator {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
Grade ob=new Grade();
System.out.println("enter the name of students");
for(int i=0;i<5;i++)
{
System.out.println((i+1)+"student");
names[i]= sc.nextLine();
}
System.out.println("enter the test scores of students");
for(int i=0;i<5;i++)
{
System.out.println("STUDENT "+(i+1));
for(int j=0;j<4;j++)
{
System.out.println("TEST "+(j+1));
testscore[i][j]=sc.nextDouble();
if(testscore[i][j]>100)
{
System.out.println("in appropriate value TRY AGAIN");
j--;
continue;
}
}
}
System.out.println("OK INPUT COMPLETE WANT TO KNOW THE FULL RESULTS Y/N");
String resp=sc.next();
ob.calculate(testscore);
if(resp.equals("Y"))
{
System.out.println("------------DISPLAYING RESULTS-----------") ;
System.out.println("STUDENT NAME GRADES");
for(int i=0;i<5;i++)
{
System.out.println(names[i]+" "+grades[i]);
}
System.out.println("want to check individual scores enter the student number");
int n=sc.nextInt();
try
{
System.out.println("STUDENT NAME "+names[n-1]+" GRADES "+grades[n-1]);
System.out.println("INDIVIDUAL TEST SCORES");
for(int i=0;i<4;i++)
{
System.out.println(testscore[n-1][i]);
}
}
catch(Exception e)
{
System.out.println("this student does not exist");
}
}
else
{
System.out.println("CLOSING");
}
}
}
Please DONT forgot to rate my answer. We are working hard for you Guys!!
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.