Question

PLEASE HELP, Java question. I posted this question before and had no reply. Attached Files: diving_data.txt...

PLEASE HELP, Java question. I posted this question before and had no reply.

Attached Files:

File diving_data.txt (411 B)

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

File readFile.java (722 B)

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 str = null;
        double score = 0.0;
        //I know there are 9 lines of data
        for(int l=0; l<9; l++) {
   //System.out.println("The data from line " + l);
   str = infile.next();
   System.out.print(str + " ");
   str = infile.next();
   System.out.print(str + " ");
   //I know there are 8 scores per diver
   for(int s=0; s<8; s++) {
    score = infile.nextDouble();
       System.out.print(score + " ");
   }
   System.out.println();
  }

 }

}

NOTE: The difference between this assignment 11 and assignment 10:

This version requires the Diver class/object and the Diver object instances (1/Diver) will contain the data pertaining to each Diver and their respective scores!

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

Diver UML

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:

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

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.

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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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"));

ArrayList<Diver> divers = new ArrayList<>();

String str = null;

double score = 0.0;

// I know there are 9 lines of data

for (int l = 0; l < 9; l++) {

String name = "";

name += infile.next() + infile.next();

Diver diver = new Diver(name);

// I know there are 8 scores per diver

for (int s = 0; s < 8; s++) {

score = infile.nextDouble();

diver.addScore(score);

}

divers.add(diver);

}

// Print divers

for(int i = 0; i<divers.size(); i++) {

System.out.println(divers.get(i));

}

}

public static class Diver {

private String name;

private double[] scores;

int count;

public Diver(String name) {

this.name = name;

scores = new double[8];

count = 0;

}

void addScore(double score) {

if(count < scores.length) {

scores[count++] = score;

}

}

@Override

public String toString() {

String str = String.format("%20s", name) + " => \t Input scores: ";

double outputScore = 0, min = Double.MAX_VALUE, max = Double.MIN_VALUE;

for(int i= 0; i<count; i++) {

str += String.format("%.2f ", scores[i]);

outputScore += scores[i];

if(min > scores[i]) {

min = scores[i];

}

if(max < scores[i]) {

max = scores[i];

}

}

outputScore -= (max + min);

str += " \t Output score: " + String.format("%.2f", outputScore);

return str;

}

}

}

Add a comment
Know the answer?
Add Answer to:
PLEASE HELP, Java question. I posted this question before and had no reply. Attached Files: diving_data.txt...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • quiz6

    An article in Quality Engineering ["Estimating Sources of Variation: A Case Study from Polyurethane Product Research" (1999-2000, Vol. 12, pp. 89-96)] studied the effects of additives on final polymer properties. In this case, polyurethane additives were refferred to as cross-linkers. The average domain spacing was the measurement of the polymer property. the data are as follows:Cross-Linker LevelDomain Spacing (nm)-19.399.48.99.59.1-0.759.49.29.89.59.29-0.59.69.29.49.899.109.59.49.29.29.79.80.59.88.29.39.38.810.119.49.79.59.99.29.2Is there a difference in the cross-linker level? Perform an analysis of variance. Use alpha=0.05

  • 10.5 Module 9 Homework What type of pattern exists in the data? and four-month moving averages ...

    10.5 Module 9 Homework What type of pattern exists in the data? and four-month moving averages for this time series (to 2 decimals). If your answer is zero enter O b. Develop 3-Month Moving Average Forecast Time-Series 9.1 9.4 9.7 9.9 9.8 9.8 10.7 10.1 9.8 9.6 9.6 10 Total Time-Series 4-Month Moving Month Error? 9.3 9.1 2 1 Mind Tap- CENGAGE I MINDTAP 4-Month Moving Average Forecast Error 9.1 9.4 9.7 9.9 9.8 10.7 10.1 9.8 10 9.6 12...

  • A particular talent competition has five judges, each of whom awards a score between 0 and...

    A particular talent competition has five judges, each of whom awards a score between 0 and 10 to each performer. Fractional scores, such as 8.3, are allowed. A performer’s final score is determined by dropping the highest and the lowest score received then averaging the three remaining scores. Write a program that does the following: 1. Reads names and scores from an input file into a dynamically allocated array of structures. The first number in the input file represents the...

  • Compute the correlation coefficient, r, for all five variables (columns). Interpret your findings whether you have determined any relationship between variables. X1 X2   X3 X4 X5       The data (X1, X...

    Compute the correlation coefficient, r, for all five variables (columns). Interpret your findings whether you have determined any relationship between variables. X1 X2   X3 X4 X5       The data (X1, X2, X3, X4, X5) are by city.       8 78   284 9.1 109       X1 = death rate per 1000 residents       9.3 68   433 8.7 144 X2 = doctor availability per 100,000 residents   7.5 70   739 7.2 113      X3 = hospital availability per 100,000 residents   8.9 96   1792   8.9 97 X4 = annual...

  • Ms. Blankenship’s tenth grade class is studying the impact of photoperiod on plant growth. Her students...

    Ms. Blankenship’s tenth grade class is studying the impact of photoperiod on plant growth. Her students fill 100 paper cups with potting soil and a single pea seed. Each cup is randomly assigned to one of four growth chambers. Each of the four growth chambers has an identical artificial light source (25 watts) but each has a different light (L) : dark cycle (D). Chamber 1 is set to 24L : 0D. Chamber 2 is set to 16L : 8D....

  • Compute Regression Analysis for following relationship: The relationship between death rate X1 (USD) vs. population density...

    Compute Regression Analysis for following relationship: The relationship between death rate X1 (USD) vs. population density X5. Population as a Predictor, X, then death rate as a Response variable, Y. Get Regression Output, and Scatter plot between these variables and compute Coefficient of Determination, R2, and Interpret your findings. X1  X2  X3   X4     X5   The data (X1, X2, X3, X4, X5) are by city.       8   78   284   9.1   109   X1 = death rate per 1000 residents       9.3   68   433   8.7   144...

  • Question Help Baseball teams in League 1 play their games with a rule that they believe...

    Question Help Baseball teams in League 1 play their games with a rule that they believe produces more runs and generates more interest among fans. The data shown below include the average numbers of runs scored per game by League 1 and League 2 teams for one season. Complete parts a through d. L L League 111.3 10.7 League 2 10.7 10.1 10.3 9.8 10.2 9.3 10.2 9.3 9.6 9.3 9.5 9.2 9.5 9.1 9.4 8.9 9.1 8.8 8.8 8.8...

  • I need a help with my lab, I write all data that get. 355 SERIES SINUSOIDAL...

    I need a help with my lab, I write all data that get. 355 SERIES SINUSOIDAL CIRCU CUITS neeseed 000 10 mH 10 kHz + R E-8V(Pp) V 1 kn Channel 2 Vert: 1 Vidiv Hor: 20 us/div. Channel 1 Vert: 1 Vidiv Hor: 20 us/div. FIG. 9.1 (b) After setting E to 8 V (p-p), determine the peak-to-peak voltage for Ve from chan- nel 2 and record in the top row of Table 9.1 Determine the phase angle 8,...

  • An object of weight 1 N is falling vertically. The time vs. speed data can be...

    An object of weight 1 N is falling vertically. The time vs. speed data can be found here. In this case the effect of air-drag cannot be neglected. Use your critical thinking to estimate the air-drag coefficient . Make sure you include the units in your answer. 0   0 0.1   0.9992 0.2   1.993 0.3   2.978 0.4   3.948 0.5   4.898 0.6   5.826 0.7   6.728 0.8   7.599 0.9   8.438 1   9.242 1.1   10.01 1.2   10.74 1.3   11.43 1.4   12.09 1.5   12.7 1.6  ...

  • The data on the below shows the number of hours a particular drug is in the...

    The data on the below shows the number of hours a particular drug is in the system of 200 females. Develop a histogram of this data according to the following intervals: Follow the directions. Test the hypothesis that these data are distributed exponentially. Determine the test statistic. Round to two decimal places. (sort the data first) [0, 3) [3, 6) [6, 9) [9, 12) [12, 18) [18, 24) [24, infinity) 34.7 11.8 10 7.8 2.8 20 9.8 20.4 1.2 7.2...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT