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

Write a java program which: 1. Prompts the user for 5 test scores as integers gr

ID: 3825995 • Letter: W

Question

Write a java program which:
1. Prompts the user for 5 test scores as integers greater than or equal to zero and less than or equal to 100.

2. Validates that the user entries are valid (integers greater than or equal to zero and less than or equal to 100).

3. Stores the 5 tests scores in an array.

4. Uses the bubble sort to sort the scores in ascending order.

5. Calculates the letter grade for each test

6. Displays the letter grade of each score as well as the overall average (the average of the 5 tests).
SPECIFIC REQUIREMENTS
1. You must include a method called calcAverage to compute the average of the 5 test scores; it takes an array of type int as a parameter and returns the average.

2. You must include a method called validateUserInput to ensure user entries are integers greater than or equal to zero and less than or equal to 100.

4. You must include a method called bubbleSort which sorts the values (test scores) stored in the array in ascending order.

5. You must include a method called displayTestScores which displays each test score and its corresponding letter, as well as the overall average.

GENERAL RESTRICTIONS
1. No infinite loops, examples include:
a. for(;;)
b. while(1)
c. while(true)
d. do{//code}while(1);

2. No break statements to exit loops

Output:

Letter score Grade 90 80 and

Explanation / Answer

TestScoresOperations.java

import java.util.Scanner;

public class TestScoresOperations {

   public static void main(String[] args) {
       Scanner scan = new Scanner(System.in);
       int scores[] = new int[5];
       char grades[] = new char[5];
       for (int i = 0; i < scores.length; i++) {
           System.out.println("Enter score " + (i + 1) + ": ");
           scores[i] = scan.nextInt();
           if (!validateUserInput(scores[i])) {
               i--;
           }
       }
       determineGrade(scores, grades);
       displayTestScores(scores, grades);
   }

   public static boolean validateUserInput(int X) {
       if (X < 0 || X > 100) {
           System.out
                   .println("that is not an integer X such that: 0<=X <=100, try again ");
           return false;
       }
       return true;
   }

   public static double calcAverage(int scores[]) {
       int sum = 0;
       for (int i = 0; i < scores.length; i++) {
           sum = sum + scores[i];
       }
       return sum / (double) scores.length;
   }

   public static void determineGrade(int scores[], char grades[]) {
       char grade;
       for (int i = 0; i < scores.length; i++) {
           if (scores[i] >= 90) {
               grade ='A';

           } else if (scores[i] >= 80 && scores[i] < 90) {
               grade ='B';

           } else if (scores[i] >= 70 && scores[i] < 80) {
               grade ='C';

           } else if (scores[i] >= 60 && scores[i] < 70) {
               grade ='D';
           }
           else{
               grade ='F';
           }
           grades[i]= grade;
       }
   }
   public static void displayTestScores(int scores[], char grades[]) {
       bubbleSort(scores);
       System.out.println("Score LetterGrade");
      
       for (int i = 0; i < scores.length; i++) {
           System.out.println(scores[i]+" "+grades[i]);
       }
       System.out.println("The average is "+calcAverage(scores));
      
   }
   public static void bubbleSort(int[] scores) {
  

int n = scores.length;
int temp = 0;

for(int i=0; i < n; i++){
for(int j=1; j < (n-i); j++){

if(scores[j-1] > scores[j]){
//swap the elements!
temp = scores[j-1];
scores[j-1] = scores[j];
scores[j] = temp;
}

}
}

}
}

Output:

Enter score 1:
90
Enter score 2:
1002
that is not an integer X such that: 0<=X <=100, try again
Enter score 2:
89
Enter score 3:
78
Enter score 4:
83
Enter score 5:
71
Score   LetterGrade
71   A
78   B
83   C
89   B
90   C
The average is 82.2

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