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

This is due at Midnight Central Time: Description A teacher has ve students who

ID: 3535299 • Letter: T

Question

This is due at Midnight Central Time:

Description A teacher has ve 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

The student and score data are stored in the given le StudentInfo.txt. Create a class named GradeBook in a le named GradeBook.java. The class GradeBook is required to use a String array to hold the ve students' names, an array of ve characters to hold the ve students' letter grades, and ve arrays of four doubles each to hold each student's set of test scores. The class should have methods that return a speci c student's name, average test score, and a letter grade based on the average.

The partial program that demonstrates the class GradeBook is given in the le Grade-BookDemo.java. You are required to read and understand the given program, and then ll in the missing code in GradeBookDemo.java to make the program complete and work properly with the class GradeBook. The sample output of the program is given in the SampleOutput.txt. Do NOT make any change in the given program except the location where you are required to insert code.

Here is the text in the StudentInfo.txt file:

Joanne Smith

98

89

100

76

Will Jones

67

89

91

88

Kerry McDonald

78

79

88

91

Sam Young

88

98

76

56

Jill Barnes

94

93

91

98

I am completely lost at this point. I am frustrated. I am mostly having trouble with reading the data in from the file.


GradeBook.java

public class GradeBook

{

// Constant for the number of students

private final int NUM_STUDENTS = 5;


// Constant for the number of tests

private final int NUM_TESTS = 3;


// Array to hold student names

private String[] names = new String[NUM_STUDENTS];


// Array to hold student grades

private char[] grades = new char[NUM_STUDENTS];


// Create arrays of scores, one for each student.

private double[] scores1 = new double[NUM_TESTS];

private double[] scores2 = new double[NUM_TESTS];

private double[] scores3 = new double[NUM_TESTS];

private double[] scores4 = new double[NUM_TESTS];

private double[] scores5 = new double[NUM_TESTS];


/**

The setName method assigns a student's name.

*/


public void setName(int studentNumber, String name)

{

names[studentNumber-1] = name;

}


/**

The setScores method copies an array of test scores

to a student's array of scores.

*/


public void setScores(int studentNumber, double[] scores)

{

switch(studentNumber)

{

case 1:copyArray(scores1,scores); break;

case 2:copyArray(scores2,scores); break;

case 3:copyArray(scores3,scores); break;

case 4:copyArray(scores4,scores); break;

case 5:copyArray(scores5,scores); break;

default:break;

}

}


/**

The getName method returns a student's name.

*/


public String getName(int studentNumber)

{

return names[studentNumber-1];

}


/**

The getAverage method returns a student's average

test score.

*/


public double getAverage(int studentNumber)

{

double avg=0.0;

switch(studentNumber)

{

case 1:avg = calcAverage(scores1); break;

case 2:avg = calcAverage(scores2); break;

case 3:avg = calcAverage(scores3); break;

case 4:avg = calcAverage(scores4); break;

case 5:avg = calcAverage(scores5); break;

default:break;

}

return avg;

}


/**

The getLetterGrade method returns a student's

letter grade.

*/


public char getLetterGrade(int studentNumber)

{

char lettergrade; //your code

if(getAverage(studentNumber)>=90 && getAverage(studentNumber)<=100)

lettergrade = 'A';

else if(getAverage(studentNumber)>=80 && getAverage(studentNumber)<=89)

lettergrade = 'B';

else if(getAverage(studentNumber)>=70 && getAverage(studentNumber)<=79)

lettergrade = 'C';

else if(getAverage(studentNumber)>=60 && getAverage(studentNumber)<=69)

lettergrade = 'D';

else

lettergrade = 'E';

return lettergrade;



}


/**

The copyArray method copies the contents of

one array to another.

*/


private void copyArray(double[] to, double[] from)

{

System.arraycopy(from, 0, to, 0, from.length);

}


/**

The calcAverage method calculates the average

of the values in an array of test scores.

*/


private double calcAverage(double[] scores)

{

double sum=0;

for(int i=0; i<scores.length; i++)

sum+=scores[i];

return sum/scores.length;


}


/**

The determineGrade method determines the letter

grade for a test average.

*/


public char LetterGrade(double average)

{

char lettergrade;

if(average>=90 && average<=100)

lettergrade = 'A';

else if(average>=80 && average<=89)

lettergrade = 'B';

else if(average>=70 && average<=79)

lettergrade = 'C';

else if(average>=60 && average<=69)

lettergrade = 'D';

else

lettergrade = 'E';

return lettergrade;

}

}




GradeBookTest.Java

import java.util.Scanner;

import java.io.*;


/**

* GradeBookDemo program

* This program tests the GradeBook class by

* using the data stored in the StudentInfo.txt

* file.

*/


public class GradeBookTest

{

public static void main(String[] args)

throws IOException

{

// Create a GradeBook object.

GradeBook gb = new GradeBook();


// Read the data from the file and put the data into grade book gb

readFromFile(gb);

// Display the student data.

for (int i = 1; i <= 5; i++)

{

System.out.println("Name : " + gb.getName(i) +

" Average score: " +

gb.getAverage(i) +

" Grade: " +

gb.getLetterGrade(i));

}

}



/**

* readFromFile method

*/

public static void readFromFile(GradeBook gb)

throws IOException

{

/* Missing code start here */

int i = 0;

final int NUM_STUDENTS = 5;

String[] names = new String[ NUM_STUDENTS];

//Open the file

File file = new File ("StudentInfo.txt");

Scanner inputFile = new Scanner (file);

//Read the file

while (inputFile.hasNext())

{

names[i] = inputFile.nextLine();

i++;

}

//Close the file

inputFile.close();




/* Missing code end here */

}

}

Explanation / Answer

public class Grades

{ // Begin public class Grades

private double[] testScores; // Variable that will ref an array of test scores

/**

Constructor

@param scoreArray An array of test scores

*/

public Grades(double[] scoreArray)

{ // Assign the array argument to the testScores field

testScores = scoreArray;

}

/**

getAverage method

@return The average of the test scores

*/

public double getAverage()

{ // Begin public double getAverage()

double total = 0; // To hold the score total

double average; // To hold the average

// If array contains less than 4 test scores, display error message and set

// average to 0

if (testScores.length < 4)

{ // Begin if statement

System.out.println("Error: You must have atleast " +

"four test scores!");

average = 0;

} // End if statement

else

{ // Begin else statement

// Calculate total of the scores

for (double score : testScores)

total += score;

// Get the average of the scores

average = total / (testScores.length - 1);

} // End else statement

// Return the average of the test scores

return average;

} // End public double getAverage()

} // End public class Grades

import java.text.DecimalFormat; // Needed to format test score average

import javax.swing.JOptionPane; // Needed for showInputDialog & showMessageDialog

public class calcAverage

{ // Begin public class calcAverage

static DecimalFormat formatter = new DecimalFormat("###.##"); // Global decimal formatter

public static void main(String[] args)

{ // Begin public static void main(String[] args)

int numScores; // To hold the number of scores

String studNames; // To hold the names of the students

// Get the number of test scores

System.out.println("How many test scores do you have? ");

numScores = keyboard.nextInt();

// Get the names of the students

System.out.println("Please enter the student's name ");

// Create an array to hold the test scores

double[] scores = new double[numScores];

// Create an array to hold the names of the students

String[] names = new String[studNames];

// Get the test scores and store them in the scores array

for (int index = 0; index < numScores; index++)

{ // Begin for loop

System.out.println("Enter score" +

(index + 1) + ": ");

scores[index] = keyboard.nextDouble();

} // End for loop

// Create a Grades object, passing the scores array as an argument to the constructor

Grades myGrades = new Grades(scores);

// Display the average of the test scores

System.out.println("Your test score average is " +

myGrades.getAverage());

} // End public static void main(String[] args)

} // End public class calcAverage

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote