Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Objectives In completing this project, you will gain experience with the following Java features: the Scanner class selection structures loops file input-output clean code Problem

Objectives

In completing this project, you will gain experience with the following Java features:

  • the Scanner class
  • selection structures
  • loops
  • file input-output
  • clean code

Problem Statement

Processing large amount of data to obtain statistical information is a frequent computer application in many areas. The most frequently calculated parameters are the average, the median and the population standard deviation.

In this project you implement a program that

  • reads test scores from a file
  • determines the total number of scores in the file
  • calculates the average score
  • determines the maximum score and the minimum score
  • calculates the population standard deviation
  • determines the number of tests in each of the letter grade groups A, B, C, D, F
  • makes the output message displayed on the console, and writes the output to a file, as well

Analysis and Requirements

Input

  • named constants to store the lower score limits for the letter grade groups, these are 90, 80, 65, 55, 0 in the order of grades A, B, C, D
  • an undetermined number of tests scores stored on an external input file; each number is an integer between 0 and 100
  • the name of the input file to be solicited from the user on the console

Output

The output will contain the following data:

  • The total number of tests
  • The average score
  • The population standard deviation of the scores
  • The minimum score
  • The maximum score
  • The number as well as the percentage of scores in each letter grade group

A template to be followed in displaying the output is shown below (Figure 1). Your actual output may have other numerical values.

test Statistics

Total: 79

Average score: 69.38

Population standard deviation of the scores: 19.32

# of A, 85-100: 7 8.86%

# of B, 75--84: 20 25.32%

# of C, 65--74: 31 39.24%

# of D, 55--64: 7 8.86%

# of F, 00--54: 14 17.72%

Minimum score: 15

Maximum score: 96

Figure 1

Note that all decimal numbers must be rounded to two decimals, and all the score listing lines must contain 10 numbers (except may be the last one).

Formulas needed

Average: The average score is the sum of the individual scores divided by the total number of scores. Avoid integer division. If N is the total number of scores and x1, x2, , xN are the score values then

average = (x1+x2++xN)/N

Population standard deviation: The difference of each score and the average squared, added, divided by N, and take the square root of the result.

psd * psd = ((average x1)2+(average x2)2++(average - xN)2)/N

Design

For this project you shall define a classes named testStatistics.

Add four static named constant fields to store the lower limits of the grade groups, see in Input above. These variable are declared in the class but outside of the main method.

Within the main method, create commented places for codes responsible for various tasks.

//Declare variables

You will need

  • six integer variables for counting; one counter variable is used to count the total number of scores on the file, and one additional variable is needed to count the scores for each of the grades A, B, C, D and F
  • three integer variables minScore, maxScore, nextScore; minScore and maxScore are used to store the lowest and highest score values, nextScore stores score currently read from the file
  • three double variables to store sum, average and psd
  • two String variables to store the output message and the file name

// Declare and instantiate a Scanner object for console reading

// Declare and instantiate a File object to the file name solicited and received from the

console

// Check if the file exists and repeat file name solicitation until the name accepted (a loop

will be used)

// Declare and instantiate another Scanner object reader to read data from the file

// Run a while loop to read, count and sum the scores (running total); the loop must also have logic to determine maxScore, minScore, and must count the occurrences of scores in the grade groups; input values are checked, wrong input are not counted and they are ignored in the processing (the loop continues at the next iteration if wrong input was found). Wrong input does not update any of the counter variables, neither the sum, maxScore and minScore variables.

// Compute the average

// Re-instantiate the file reader Scanner object

// Run a for loop that makes the summation for psd, see the formula for psd

// Compute psd

// Compose the output message

// Display the message on the console

// Instantiate a PrintWriter object and write the output to a file named testStatFile

Implementation Requirements and Hints

  • You must have a comment block preceding the header of each of your classes that has the following content: /* * * CS 16000-04 05/06/06, Spring Semester 2021

* (Specify your own lab section only) * Project 2: test Statistics * * Description. * */

  • Having the name of the input file read from the console, the name shall be saved in a variable, say inputFileName
  • To validate the file name
  1. declare a File object
  2. run a while loop in which solicit, read and save a candidate for the file name
  3. instantiate the File object to the file name
  4. check if the file exists, if it does not, continue the loop, otherwise stop the loop
  • In the while loop that reads the scores from the file
  1. Save the currently read input in nextScore
  2. Validate the input; wrong input not processed, the loop turns to the next iteration
  3. Update the total counter
  4. Check if nextScore is greater than maxScore, if so update maxScore with nextScore
  5. Repeat the checking for minScore
  6. Apply a nested if else if structure to determine the grade group relevant for nextScore and update the group counter
  7. Add nextScore to sum
  • After the loop, compute average by applying the average formula; care for the integer division, average must be exact
  • Note that the score data are not stored internally by the program, and to compute the standard deviation (psd) the average is already must be known. Therefore, average and psd cannot be simultaneously determined in one file reading process. In order to compute the value of psd, the file inputFileName must be read once more by a new Scanner
  • As for the second reading of the file, a for loop is applicable since the total number of admissible items in the file is known. Input evaluation is still necessary to discard the wrong inputs. You may decide if you want to use a while loop for the second reading, or you want to apply a for loop.
  • Having the second loop completed and psd determined, the output message containing the obtained results must be built; decimal numbers in the output must be formatted and rounded to two digits after the point
  • Declare and instantiate a PrintWriter object to write the output to a file named ScoreStatistics.txt
  • Print the output to console and write output to file as required

  • Start your work on this project without delay.

Testing

Run your code with the supplied text file to_test.txt and use the data of Figure 2 for correctness. If the program is working correct, run the program with the input file test_scores.txt as well.

test Statistics

Total: 11

Average score: 69.91

Population standard deviation of the scores: 17.22

# of A, 85-100: 2 18.18%

# of B, 75--84: 2 18.18%

# of C, 65--74: 2 18.18%

# of D, 55--64: 3 27.27%

# of F, 00--54: 2 18.18%

Minimum score: 44

Maximum score: 100

I cannot attach the documents

testscores.txt has

57 80 100 95 55 78 61 53 84 34 69 74 70 74 71 87 26 83 83 79 37 74 85 67 38 82 72 38 74 16 81 81 80 92 82 86 64 56 69 41 81 80 71 59 71 81 77 68 88 67 58 43 75 96 72 81 42 62 75 85 50 90 75 48 56 70 73 71 87 83

Scores.txt has

78 53 84 34 69 74 70 74 71 87 37 74 85 67 38 82 72 38 74 16 81 81 80 92 82 86 64 56 69 41 81 80 71 59 71 81 77 68 88 67 58 43 75 96 72 81 42 62 75 85 66 65 77 63 85 78 89 72 49 77 81 83 57 59 63 77 79 57 69

to_test.txt has

57 80 100 95 55 -12 71 61 44 53 84 155 69 100 93 17 79

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems Uropean Conference Adbis 2020 Lyon France August 25 27 2020 Proceedings Lncs 12245

Authors: Jerome Darmont ,Boris Novikov ,Robert Wrembel

1st Edition

3030548317, 978-3030548315

More Books

Students also viewed these Databases questions