A teacher has five students who have taken four tests The te

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: Write a class that uses a String array or an ArrayList object to hold the five students\' names, an array of five characters to hold the five students\' 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, the 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. Modify the grade book application in Programming Challenge 8 so that it drops each student\'s lowest score when determining the test score averages and letter grades.

Solution

public class Student{
private String name;
private double[] test = new double[4];


public Student(){
name = \" \";
}

public Student(String n, double[] t){
name = n;
test = t;
}

public void setName(String n)
{
name = n;
}

public String getName(){
return name;
}

public void setTest(double t,int i)
{
test[i] = t;
}

public double getTest(int i)
{
return test[i];
}


public double getTestAvg(){

double sum = 0;
double avg;
for(int i = 0; i < test.length; i++)
{
sum += test[i];
}
avg = sum / test.length;
return avg;
}

public char getLetterGrade(){

double average = getTestAvg();
char grade=0;

if(average >= 90)
grade = \'A\';
else if (average >= 80)
grade = \'B\';
else if (average >= 70)
grade = \'C\';
else if (average >=60)
grade = \'D\';
else if (average < 60)
grade = \'F\';

return grade;
}

public String toString(){
String str = \"\";
str += \"\ Name of student: \" + name;
str += \"\ Average test score: \" + getTestAvg();
str += \"\ Letter grade: \" + getLetterGrade();
return str;
}
}


import java.util.Scanner;
import java.io.*;

public class GradeBook {

public static void main(String[] args) throws IOException {

Student[] students = new Student[5];

getStudentData(students);

}

public static double getStudentData(Student[] array) {
Scanner scan = new Scanner(System.in);
String[] student = new String[5];
double[] test = new double[4];
for (int i = 0; i < student.length; i++) {
System.out.println(\"Enter the name of the student : \");
student[i] = scan.nextLine();
for (int j = 0; j < test.length; j++) {
System.out.println(\"Enter score \" + (j + 1) + \" for the student\");
test[j] = scan.nextDouble();
scan.nextLine();
}
array[i] = new Student(student[i], test);

}
return 0;

}
}

 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
 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

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site