Please help, JAVA QUESTION. Read carefully and please explain. NOTE: The differe
ID: 3714818 • Letter: P
Question
Please help, JAVA QUESTION. Read carefully and please explain.
NOTE: The difference between this assignment 10 and assignment 11:
Attached Files:
There is no Diver class/object for assignment 10 (ie the data is all saved and processed using arrays!
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.
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
//readFile.java
import java.io.*;
import java.util.*;
public class readFile {
static Scanner infile = null;
public static void main(String[] args) throws IOException {
infile = new Scanner(new FileReader("diving_data.txt"));
String firstName,lastName = null;
ArrayList<String> diverName = new ArrayList<String>();
Map<String, Double> diverOutput = new HashMap<String, Double>();
double diverScore[] = new double[8];
double score = 0.0;
int count =1;
double n = 0;
//I know there are 9 lines of data
for(int l=0; l<9; l++) {
firstName = infile.next();
lastName = infile.next();
diverName.add(firstName+" "+lastName);
//I know there are 8 scores per diver
for(int s=0; s<8; s++) {
score = infile.nextDouble();
diverScore[s] = score;
}
double min = diverScore[0]; // assume first elements as smallest number
double max = diverScore[0]; // assume first elements as largest number
for (int i = 0; i < diverScore.length; i++)
{
if (diverScore[i] > max)
{
max = diverScore[i];
}else if (diverScore[i] < min)
{
min = diverScore[i];
}
//adding the scores
n += diverScore[i];
}
for (int i = 0; i < diverScore.length; i++)
{
//Finding how many times lowest score has repeated
if(diverScore[i] == min){
count++;
}
}
diverOutput.put(firstName+" "+lastName, (n-max-min*count));
count = 0;
n =0;max =0;min=0;
}
for(Map.Entry<String, Double> iter: diverOutput.entrySet())
System.out.println(iter.getKey()+" "+iter.getValue());
}
}