java In a gymnastic or diving competition each contestants s

 java    In a gymnastic or diving competition, each contestant\'s score is calculated by     dropping the lowest and highest scores and then adding the remaining scores. Write    a JAVA program that first asks user to enter the number of contestants. Then the     program should read the score of 8 judge\'s for each contestant.    The program should display    a) the total score of each contestant    b) the highest total score amongst the contestants    c) the lowest total score amongst the contestants        Your input file for score should look like     9.2 9.3 9.0 9.9 9.5 9.5 9.6 9.8        Hint: Use 2-D array 

Solution

ContestantWeightTest.java

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;


public class ContestantWeightTest {

  
   public static void main(String[] args) throws FileNotFoundException {
       File file = new File(\"D:\\\\input.txt\");
       Scanner scan = new Scanner(System.in);
       System.out.print(\"Enter the number of contestants: \");
       int n= scan.nextInt();
       double contestant[][] = new double[n][8];
       Scanner scan1 = new Scanner(file);
       double total = 0;
       int i = 0;
       while(i<n){
           String record = scan1.nextLine();
           String weights[] = record.split(\" \");
           for(int j=0; j<weights.length; j++){
               contestant[i][j] = Double.parseDouble(weights[j]);
           }
           i++;
       }
       double max = contestant[0][0];
       double min = contestant[0][0];
       double totalMax = Double.MIN_VALUE;
       double totalMin = Double.MAX_VALUE;
       for(i=0; i<contestant.length; i++){
           total = 0;
           for(int j=0; j<contestant[i].length; j++){
               if(max < contestant[i][j]){
                   max = contestant[i][j];
               }
               if(min > contestant[i][j]){
                   min = contestant[i][j];
               }
               total = total + contestant[i][j];
           }
           total = (total-min-max);
           System.out.println(\"The total score of each contestant: \"+total);
           if(totalMax < total){
               totalMax = total;
           }
           if(totalMin > total ){
               totalMin = total;
           }
          
       }
       System.out.println(\"The highest total score amongst the contestants: \"+totalMax);
       System.out.println(\"The lowest total score amongst the contestants: \"+totalMin);
      
   }

}

Output:

Enter the number of contestants: 4
The total score of each contestant: 56.9
The total score of each contestant: 55.9
The total score of each contestant: 55.9
The total score of each contestant: 55.6
The highest total score amongst the contestants: 56.9
The lowest total score amongst the contestants: 55.6

input.txt

9.2 9.3 9.0 9.9 9.5 9.5 9.6 9.8
9.2 9.1 9.0 9.9 9.2 9.5 9.6 9.4
9.2 9.2 9.1 9.0 9.5 9.5 9.6 9.8
9.2 9.2 9.1 9.1 9.5 9.5 9.6 9.3

 java In a gymnastic or diving competition, each contestant\'s score is calculated by dropping the lowest and highest scores and then adding the remaining score

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site