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

for drjava please Create a Diver java class per the following Diver uml diagram:

ID: 3714168 • Letter: F

Question

for drjava please

Create a Diver java class per the following Diver uml diagram:

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 row of data create an instance of a Diver object from that row of data. Output each diver's name, all of her scores and a 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, the attached ReadFile.java file shows the logic for reading each row of data. Once all the data has been read and the Diver instances created (and saved). Output each Diver's name, all her scores and the calculated total score for that Diver. Where total points is calculated based on the scoring rule defined above.

A couple of points regarding the above uml diagram:

1.addScore(double pScr) // is a convenience method that adds a single score to the scores ArrayList as a time.

2.calculateTotalScore() //is another convenience method that calculates a Diver's total score according to the rules below regarding how the total score is arrived at.

3.toString() //build's a string consisting of the Diver's first and last name and all the Diver's individual scores contained in the scores ArrayList and the Diver's resulting total score.

Either a main method may be added to the Diver class for testing or a separate program may be written. As a row of data is read an Instance of a Diver object needs to be created, it's data fields populated and the Diver object needs to be added to a separate ArrayList. For each Diver output the diver's name and total score using the provided scoring rules. Each contestant's score is calculated by dropping the lowest and highest scores and then adding the remaining scores. 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.

Attached Files

Second Attached file

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

Please find my code:



import java.util.ArrayList;
public class Diver {
private String firstName;
private String lastName;
private ArrayList<Double> scores;
public Diver()
{
scores = new ArrayList<Double>();
}
public Diver(String fname, String lname)
{
firstName = fname;
lastName = lname;
}
public void addScore(double score)
{
scores.add(score);
}
public String toString()
{
String str = String.format("%-25s ", firstName + " " + lastName);
for(int i = 0; i < scores.size(); i++)
str += String.format("%5.1f", scores.get(i));
str += String.format("%5.1f", calculateTotalScore());
return str;
}
public double calculateTotalScore()
{
double high = 0;
double low = 0;
double total = 0;
if(scores.size() != 0)
{
low = high = scores.get(0);
for(Double s : scores)
{
if(s > high)
high = s;
if(s < low)
low = s;
total += s;
}
}
total = total - (high +low);
return total;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public ArrayList<Double> getScores() {
return scores;
}
public void setScores(ArrayList<Double> scores) {
this.scores = scores;
}
}


===========
ReadFile.java
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
public class ReadFile {
public static void main(String[] args) throws IOException {
Scanner infile = new Scanner(new FileReader("diving_data.txt"));

ArrayList<Diver> divers = new ArrayList<Diver>();
for(int row = 1; row <= 9; row++)
{
Diver d = new Diver();
d.setFirstName(infile.next());
d.setLastName(infile.next());
for(int i = 1; i <= 8; i++)
d.addScore(infile.nextDouble());
System.out.println(d);
}
infile.close();
//display the details
for(int i =0; i < divers.size(); i++)
System.out.println(divers.get(i));
}
}

output
======
Chen Ruolin 9.2 9.3 9.0 9.9 9.5 9.5 9.6 9.8 56.9
Emilie Heymans 9.2 9.2 9.0 9.9 9.5 9.5 9.7 9.6 56.7
Wang Xin 9.2 9.2 9.1 9.9 9.5 9.6 9.4 9.8 56.7
Paola Espinosa 9.2 9.3 9.2 9.0 9.5 9.3 9.6 9.8 56.1
Tatiana Ortiz 9.2 9.3 9.0 9.4 9.1 9.5 9.6 9.8 56.1
Melissa Wu 9.2 9.3 9.3 9.7 9.2 9.2 9.6 9.8 56.3
Marie-Eve Marleau 9.2 9.2 9.2 9.9 9.5 9.2 9.3 9.8 56.2
Tonia Couch 9.2 9.0 9.1 9.5 9.2 9.3 9.4 9.6 55.7
Laura Wilkinson 9.7 9.1 9.3 9.4 9.5 9.4 9.6 9.2 56.4