Attached Files: File diving_data.txt (411 B) Write program in java In a diving c
ID: 3580931 • Letter: A
Question
Attached Files: File diving_data.txt (411 B)
Write program in 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.
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.
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
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
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
public class Main{
public static void main(String[] args){
String filename = "data.txt";
try{
FileReader fileReader = new FileReader(filename);
BufferedReader bufferedReader = new BufferedReader(fileReader);
List<String> lines = new ArrayList<String>();
String line = null;
while ((line = bufferedReader.readLine()) != null){
lines.add(line);
}
bufferedReader.close();
String[] linesHere = lines.toArray(new String[lines.size()]);
String[][] names = new String[9][10];
for(int row=0;row<9;row++){
String line1 = linesHere[row];
String val[] = line1.split(" ");
for(int col = 0; col<10;col++){
names[row][col] = val[col];
}
}
for(int i=0;i<9;i++){
float sum=0;
for(int j=2;j<10;j++){
sum += Float.parseFloat(names[i][j]);
}
System.out.println(names[i][0]+" "+names[i][1]+ ":" + sum);
}
}catch(IOException e){
// Print out the exception that occurred
System.out.println("Unable to create "+filename+": "+e.getMessage());
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.