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

I am trying to make it drop the lowest score when determining the score and grad

ID: 3820579 • Letter: I

Question

I am trying to make it drop the lowest score when determining the score and grade This is my reattempt at this.

thanks

The GradeBook class stores data about student grades
for the Grade Book programming challenge.
*/

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 = 4;

// 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.
@param studentNumber The student's number.
@param name The student's name.
*/

public void removeLowest(double lowGrade)
double score;
{
{
// loop through rows of grades array
for ( double NUM_TESTS[] : scores )
{
// loop through columns of current row
for ( double grade : NUM_TESTS )
{
// if grade less than lowGrade, assign it to lowGrade
if ( grade < lowGrade )
lowGrade = grade;
} // end inner for
} // end outer for

return lowGrade; // return lowest grade
} // end method getMinimum

}

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.
@param studentNumber The student's number.
@param scores An array of test scores.
*/

public void setScores(int studentNumber, double[] scores)
{
if (studentNumber == 1)
copyArray(scores1, scores);
else if (studentNumber == 2)
copyArray(scores2, scores);
else if (studentNumber == 3)
copyArray(scores3, scores);
else if (studentNumber == 4)
copyArray(scores4, scores);
else if (studentNumber == 5)
copyArray(scores5, scores);
assignGrade(studentNumber);
}

/**
The getName method returns a student's name.
@param studentNumber The specified student's number.
@return The student's name.
*/

public String getName(int studentNumber)
{
return names[studentNumber - 1];
}

/**
The getAverage method returns a student's average
test score.
@param studentNumber The specified student's number.
@return The student's average test score.
*/

public double getAverage(int studentNumber)
{
double average;
  
if (studentNumber == 1)
average = calcAverage(scores1);
else if (studentNumber == 2)
average = calcAverage(scores2);
else if (studentNumber == 3)
average = calcAverage(scores3);
else if (studentNumber == 4)
average = calcAverage(scores4);
else if (studentNumber == 5)
average = calcAverage(scores5);
else
average = 0.0;
  
return average;
}

/**
The getLetterGrade method returns a student's
letter grade.
@param studentNumber The specified student's number.
@return The student's letter grade.
*/

public char getLetterGrade(int studentNumber)
{
return grades[studentNumber - 1];
}

/**
copyArray is a private method that copies the contents
of one array to another.
@param to The array to copy to.
@param from The array to copy from.
*/

private void copyArray(double[] to, double[] from)
{
for (int i = 0; i < to.length; i++)
to[i] = from[i];
}

/**
calcAverage is a private method that calculates
the average of the values in an array of test scores.
@param scores The array with the test scores.
*/

private double calcAverage(double[] scores)
{
double total = 0.0, average;
  
  
// Calculate the total of the scores.
for (int i = 0; i < scores.length; i++)
total += scores[i];
  

// Calculate the average.
average = total / (scores.length);
  
return average;
}

/**
assignGrade is a private method that determines and
assigns a letter grade to a specific student.
@param studentNumber The specified student's number.
*/

private void assignGrade(int studentNumber)
{
double average = getAverage(studentNumber);
grades[studentNumber-1] = determineGrade(average);
}

/**
determineGrade is a private method that determines
a letter grade for a test average.
@param average The test average.
@return The letter grade.
*/

private char determineGrade(double average)
{
char grade;
  
if (average >= 90 && average <= 100)
grade = 'A';
else if (average >= 80 && average < 90)
grade = 'B';
else if (average >= 70 && average < 80)
grade = 'C';
else if (average >= 60 && average < 70)
grade = 'D';
else if (average >= 0 && average < 60)
grade = 'F';
else
grade = '?';
  
return grade;
}
}

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

public class GradeBookDemo2
{
public static void main(String[] args)
{
// Create a GradeBook object.
GradeBook gb = new GradeBook();

// Get the data from the user.
getData(gb);
  
// Display the student data.
System.out.println("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));
}
}

/**
The getData method gets student data from the user
and populates a GradeBook object.
@param gb The GradeBook object.
*/

public static void getData(GradeBook gb)
{
String name; // To hold a name
double[] scores = new double[4]; // An array of scores

// Create a Scanner object for keyboard input.
Scanner keyboard = new Scanner(System.in);
  
// Get info for each student.
for (int student = 1; student <= 5; student++)
{
// Get the name.
System.out.print("Enter student " + student +
"'s name: ");
name = keyboard.nextLine();
gb.setName(student, name);

// Read the 4 test scores.
System.out.println("Now enter student " + student +
"'s four test scores.");
for (int i = 0; i < 4; i++)
{
System.out.print("Test score #" + (i + 1) + ": ");
scores[i] = keyboard.nextDouble();
gb.setScores(student, scores);
}

// Consume the remaining newline.
keyboard.nextLine();
}
  
System.out.println();
}
}

Explanation / Answer

import java.util.Scanner;

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 = 4;

// 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.
@param studentNumber The student's number.
@param name The student's name.
*/

public double getLowest(double scores[])
{
double lowestscore = scores[0];

// loop through rows of grades array
for (int i = 1; i < scores.length; i++)
{
if(lowestscore > scores[i])
{
lowestscore = scores[i];
}
} // end outer for
return lowestscore;
} // end method getMinimum

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.
@param studentNumber The student's number.
@param scores An array of test scores.
*/

public void setScores(int studentNumber, double[] scores)
{
if (studentNumber == 1)
copyArray(scores1, scores);
else if (studentNumber == 2)
copyArray(scores2, scores);
else if (studentNumber == 3)
copyArray(scores3, scores);
else if (studentNumber == 4)
copyArray(scores4, scores);
else if (studentNumber == 5)
copyArray(scores5, scores);
assignGrade(studentNumber);
}

/**
The getName method returns a student's name.
@param studentNumber The specified student's number.
@return The student's name.
*/

public String getName(int studentNumber)
{
return names[studentNumber - 1];
}

/**
The getAverage method returns a student's average
test score.
@param studentNumber The specified student's number.
@return The student's average test score.
*/

public double getAverage(int studentNumber)
{
double average;
  
if (studentNumber == 1)
average = calcAverage(scores1);
else if (studentNumber == 2)
average = calcAverage(scores2);
else if (studentNumber == 3)
average = calcAverage(scores3);
else if (studentNumber == 4)
average = calcAverage(scores4);
else if (studentNumber == 5)
average = calcAverage(scores5);
else
average = 0.0;
  
return average;
}

/**
The getLetterGrade method returns a student's
letter grade.
@param studentNumber The specified student's number.
@return The student's letter grade.
*/

public char getLetterGrade(int studentNumber)
{
return grades[studentNumber - 1];
}
/**
copyArray is a private method that copies the contents
of one array to another.
@param to The array to copy to.
@param from The array to copy from.
*/

private void copyArray(double[] to, double[] from)
{
for (int i = 0; i < to.length; i++)
to[i] = from[i];
}

/**
calcAverage is a private method that calculates
the average of the values in an array of test scores.
@param scores The array with the test scores.
*/

private double calcAverage(double[] scores)
{
double total = 0.0, average;
  
  
// Calculate the total of the scores.
for (int i = 0; i < scores.length; i++)
total += scores[i];
  
total -= getLowest(scores);

  
// Calculate the average.
average = total / (scores.length - 1);
  
return average;
}

/**
assignGrade is a private method that determines and
assigns a letter grade to a specific student.
@param studentNumber The specified student's number.
*/

private void assignGrade(int studentNumber)
{
double average = getAverage(studentNumber);
grades[studentNumber-1] = determineGrade(average);
}
/**
determineGrade is a private method that determines
a letter grade for a test average.
@param average The test average.
@return The letter grade.
*/

private char determineGrade(double average)
{
char grade;
  
if (average >= 90 && average <= 100)
grade = 'A';
else if (average >= 80 && average < 90)
grade = 'B';
else if (average >= 70 && average < 80)
grade = 'C';
else if (average >= 60 && average < 70)
grade = 'D';
else if (average >= 0 && average < 60)
grade = 'F';
else
grade = '?';
  
return grade;
}
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

import java.util.Scanner;

public class GradeBookDemo2
{
public static void main(String[] args)
{
// Create a GradeBook object.
GradeBook gb = new GradeBook();
// Get the data from the user.
getData(gb);
  
// Display the student data.
System.out.println("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));
}
}
/**
The getData method gets student data from the user
and populates a GradeBook object.
@param gb The GradeBook object.
*/

public static void getData(GradeBook gb)
{
String name; // To hold a name
double[] scores = new double[4]; // An array of scores
// Create a Scanner object for keyboard input.
Scanner keyboard = new Scanner(System.in);
  
// Get info for each student.
for (int student = 1; student <= 5; student++)
{
// Get the name.
System.out.print("Enter student " + student +
"'s name: ");
name = keyboard.nextLine();
gb.setName(student, name);

// Read the 4 test scores.
System.out.println("Now enter student " + student +
"'s four test scores.");
for (int i = 0; i < 4; i++)
{
System.out.print("Test score #" + (i + 1) + ": ");
scores[i] = keyboard.nextDouble();
gb.setScores(student, scores);
}

// Consume the remaining newline.
keyboard.nextLine();
}
  
System.out.println();
}
}

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