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

Write a program which takes the grades from ten quizzes and computes the average

ID: 3815851 • Letter: W

Question

Write a program which takes the grades from ten quizzes and computes the average quiz score. However, the teacher usually drops the lowest two scores. You must take this into consideration when computing the average quiz grade. Your program must implement the following methods: readQuizScore: This method asks and reads one quiz score from the console, validates the score, and then returns the score. This method will be called once for each score. computeAverage: This method takes the ten scores as input, computes the average, and returns the average. getLowestScore: This method takes the ten scores as input and returns the lowest score of the tens cores. getSecondLowestScore: This method takes the ten scores as input, and returns the second lowest score of the ten scores. Display the two lowest scores, and the correct average. Each score must be a positive value between 0.0 and 100.0. All four of the required methods must be implemented, and all must be correctly used within your program to get credit. Round the solution to two decimal places.

Explanation / Answer

import java.util.*;

class AverageScore
{
   public static void main (String[] args)
   {
         double[] score = new double[10];
       score = readQuizScore();
       double lowest = getLowestScore(score);
       double secondLowest= getSecondLowestScore(score);
       double avg = computeAverage(score);
      
       System.out.println(" Two lowest scores are "+lowest + " and "+secondLowest);
      
       avg = (avg -(lowest+secondLowest))/8; //remove 2 lowest scores and compute avg of 8 elements
       System.out.printf("Average : %.2f",avg);
      
   }
   public static double[] readQuizScore()
   {
        double[] score = new double[10];
        Scanner scan = new Scanner(System.in);
      
        System.out.println("Enter the ten scores : ");
        for(int i=0;i<10;i++)
        {
            score[i] = scan.nextDouble();
            if(score[i] < 0 || score[i] > 100)   //input validation
            {
                System.out.println("Invalid score. Try again.");
                 i--;
            }
        }
        return score;
      
   }
   public static double computeAverage(double score[])
   {
        double avg = 0;
        for(int i=0;i<10;i++)
        {
            avg = avg +score[i];
        }
      
        return avg;    //avg is sum of scores
   }
   public static double getLowestScore(double score[])
   {
        double lowest = score[0]; //lowest = first score
        for(int i=1;i<10;i++)
        {
           if(score[i] <lowest)
           lowest = score[i];
        }
        return lowest;
   }
   public static double getSecondLowestScore(double score[])
   {
        double lowest = score[0];
        double secondlowest = score[0];
      
        for(int i=1;i<10;i++)
        {
           if(score[i] <lowest)
           lowest = score[i];
        }
        for(int i=1;i<10;i++)
        {
           if(score[i] <secondlowest && score[i] >lowest) // secondlowest should be greater than lowest
           secondlowest = score[i];
        }
        return secondlowest;
   }
  
}


Output:

Enter the ten scores : 100.0 78.45 89.23 98.00 67.87 88.29 82.67 87.5 90.56 94.38

Two Lowest Scores are 67.87 and 78.45

Average : 91.33

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