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

Java In a diving competition, each contestant\'s score is calculated by dropping

ID: 3584864 • Letter: J

Question

Java

In a diving competition, each contestant's score is calculated by dropping the lowest and highest scores and then adding the remaining scores. Write a program that reads the provided data file formatted as depicted in the following table. For each diver output the diver's name and total score using the above scoring rules. Format each diver's total score to two decimal places. So for example, the output for Chen Ruolin below would be: Chen Ruolin – 56.90 points.

Diver

Score 1

Score 2

Score 3

Score 4

Score 5

Score 6

Score 7

Score 8

Chen Ruolin

9.2

9.3

9

9.9

9.5

9.5

9.6

9.8

Emilie Heymans

9.2

9.2

9

9.9

9.5

9.5

9.7

9.6

Wang Xin

9.2

9.2

9.1

9.9

9.5

9.6

9.4

9.8

Paola Espinosa

9.2

9.3

9.2

9

9.5

9.3

9.6

9.8

Tatiana Ortiz

9.2

9.3

9

9.4

9.1

9.5

9.6

9.8

Melissa Wu

9.2

9.3

9.3

9.7

9.2

9.2

9.6

9.8

Marie-Eve Marleau

9.2

9.2

9.2

9.9

9.5

9.2

9.3

9.8

Tonia Couch

9.2

9

9.1

9.5

9.2

9.3

9.4

9.6

Laura Wilkinson

9.7

9.1

9.3

9.4

9.5

9.4

9.6

9.2

Your program must read the data in from the provided data file and use arrays to store that data. Once all the data has been read in the program needs to calculate each diver's total points and output that diver's name and total points. Where total points is calculated based on the scoring rule defined above.

diving_data.txt

Diver

Score 1

Score 2

Score 3

Score 4

Score 5

Score 6

Score 7

Score 8

Chen Ruolin

9.2

9.3

9

9.9

9.5

9.5

9.6

9.8

Emilie Heymans

9.2

9.2

9

9.9

9.5

9.5

9.7

9.6

Wang Xin

9.2

9.2

9.1

9.9

9.5

9.6

9.4

9.8

Paola Espinosa

9.2

9.3

9.2

9

9.5

9.3

9.6

9.8

Tatiana Ortiz

9.2

9.3

9

9.4

9.1

9.5

9.6

9.8

Melissa Wu

9.2

9.3

9.3

9.7

9.2

9.2

9.6

9.8

Marie-Eve Marleau

9.2

9.2

9.2

9.9

9.5

9.2

9.3

9.8

Tonia Couch

9.2

9

9.1

9.5

9.2

9.3

9.4

9.6

Laura Wilkinson

9.7

9.1

9.3

9.4

9.5

9.4

9.6

9.2

Explanation / Answer

diving_data.txt

Chen Ruolin 9.2 9.3 9 9.9 9.5 9.5 9.6 9.8
Emilie Heymans 9.2 9.2 9 9.9 9.5 9.5 9.7 9.6
Wang Xin 9.2 9.2 9.1 9.9 9.5 9.6 9.4 9.8
Paola Espinosa 9.2 9.3 9.2 9 9.5 9.3 9.6 9.8
Tatiana Ortiz 9.2 9.3 9 9.4 9.1 9.5 9.6 9.8
Melissa Wu 9.2 9.3 9.3 9.7 9.2 9.2 9.6 9.8
Marie-Eve Marleau 9.2 9.2 9.2 9.9 9.5 9.2 9.3 9.8
Tonia Couch 9.2 9 9.1 9.5 9.2 9.3 9.4 9.6
Laura Wilkinson 9.7 9.1 9.3 9.4 9.5 9.4 9.6 9.2

________________

DivingData.java

import java.io.File;

import java.util.Scanner;

public class DivingData {

public static void main(String[] args) {

// Declaring variables

double score;

String fname, lname;

int ROWS = 9;

int COLS = 8;

int i = 0;

double min, max;

double sum = 0;

// Creating a two dimensional array which hold scores

double scores[][] = new double[ROWS][COLS];

// Creating array dynamically which stores firstname and lastname

String names[] = new String[ROWS];

// Opening the input file

Scanner sc = null;

try {

sc = new Scanner(new File("diving_data.txt"));

while (sc.hasNext()) {

// Reading names and populating those into an array

fname = sc.next();

lname = sc.next();

names[i] = fname + " " + lname;

// System.out.println(names[i]);

// Reading names and populating those into an scores array

for (int j = 0; j < COLS; j++) {

scores[i][j] = sc.nextDouble();

}

i++;

}

/* Finding min and maximum score in each row

* and calculate the sum except min and max scores

*/

System.out.println(" Name Total");

System.out.println(" ---- -----");

for (i = 0; i < ROWS; i++) {

min = scores[i][0];

max = scores[i][0];

for (int j = 0; j < COLS; j++) {

if (min > scores[i][j]) {

min = scores[i][j];

}

if (max < scores[i][j]) {

min = scores[i][j];

}

}

for (int k = 0; k < COLS; k++) {

/* calculating the sum of each row score

* except min and max scores

*/

if (scores[i][k] != min && scores[i][k] != max) {

sum += scores[i][k];

}

}

System.out.printf("%20s %5.2f ", names[i], sum);

sum = 0;

}

} catch (Exception e) {

System.out.println(e);

} finally {

sc.close();

}

}

}

____________________

Output:

Name Total

---- -----

Chen Ruolin 56.80

Emilie Heymans 47.60

Wang Xin 47.50

Paola Espinosa 46.70

Tatiana Ortiz 55.90

Melissa Wu 37.90

Marie-Eve Marleau 28.70

Tonia Couch 46.30

Laura Wilkinson 56.40


_____________Could you rate me well.Plz .Thank You

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