You have a class of some number of students, and each one earns a grade (from 0
ID: 3757720 • Letter: Y
Question
You have a class of some number of students, and each one earns a grade (from 0 to 100)
Your program will ask for their grades, one at a time, and will store the grades in an array
Your student grade machine will report the letter grade for each student.
It will also report the highest grade, lowest grade, and class average.
You must use a separate function to calculate the grade letter, and the highest, lowest and average grade.
You must send the entire array to the functions for highest, lowest, and average grade.
You don’t have to send the entire array for the grade letter. If you call your array students, then you can get the letter by using something like getGrade(students[x]).
Explanation / Answer
I have made common function logic for 5 studets min , max and avregare grade of students,
import java.util.Scanner;
public class Grade{
private void printAverageMinAndMax(double[] grades){
double total = 0.0;
double max = 0.0;
double min = Double.MAX_VALUE;
for(int i = 0; i < 5; i++){
double grade = grades[i];
total += grade;
if(max < grade){
max = grade;
}
if(min > grade){
min = grade;
}
}
System.out.println("Average is: " + (total / 5));
System.out.println("Max is: " + max);
System.out.println("Min is: " + min);
}
public static void main(String[] args)
{
int i;
double grade1[] = new double[5];
Scanner userInput = new Scanner (System.in);
System.out.print("Please enter the 5 students Grade used: ");
for(i = 0; i< 5; i++)
grade1[i] = userInput.nextDouble();
new Grade().printAverageMinAndMax(grade1);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.