Question
Using Java Project Description Processing a large amount of data to obtain statistical information is a frequent computer application in many areas. You will be
Using Java
Project Description
Processing a large amount of data to obtain statistical information is a frequent computer application in many areas. You will be building a program that calculates how many test scores are in a file, and the average, minimum, and maximum of the scores. You will also calculate how many scores fall above the average, and how many are at or above 70 (i.e., passing the test).
Getting the File Name
The set of values are specified in a file. You will solicit the file name from the user via the console, by printing out the message
Please enter the file name:
The program should grab the file name from the console, then check if the file exists. If it does not (or cannot be opened), the program should print out the message
File could not be opened. Please try again.
Please enter the file name:
The program will continue prompting the user for a valid file name until one is entered.
File and Output Format
The file will consist of integers separated by space. They may or may not be distributed on several lines.
For example, the grade file might contain
39 98 79 70
87 8 95
After soliciting the file name from the user and computing the appropriate information, your program should print
Number of scores: 7
Minimum: 8
Average: 68.0
Maximum: 98
Scores at or above 70: 5 (71.4%)
Scores above average: 5 (71.4%)
Here is another example. For the following grade file...
75 75 78 79 42 83 84 72 51 83
your program should print
Number of scores: 10
Minimum: 42
Average: 72.2
Maximum: 84
Scores at or above 70: 8 (80.0%)
Scores above average: 7 (70.0%)
Note some important aspects of the formatting:
All numbers should start at the same column in the terminal output.
The average should be rounded to one decimal place. The percentages of scores are also rounded to one decimal place.
Printing to File
The number of scores, minimum, average, maximum, scores at or above 70 and scores above average should all be printed to the file ExamStatFile.txt in addition to being printed to the console, using the same formatting as above.
Analysis
As you gain experience with programming, you will be able to analyze the description above and create a program to compute the desired information. However, since this is an introductory course, we will guide you through the analysis part and help you design your program.
One of the first steps in analysis is determining the inputs that your program needs and the outputs it will produce. Before reading the next part of the description, take a minute to write down the inputs and outputs.
You should have written down the following:
Inputs: file name, test scores
Output: number of scores, minimum, maximum, average, number of scores at or above 70, number of scores above the average; all of these go both to console and to file
Design
As with the analysis, as you gain experience with programming you will reach the point where you can complete the design on your own. This is where you figure out the algorithm (i.e., the steps the computer needs to take) for computing the outputs listed above.
For this assignment, the requirements listed below should help you figure out the algorithm. Your program should meet the following specifications. (The amount of points for each part is in square brackets).
As with all your code, correct compilation is critical. Appropriate deductions will be taken from the parts below for code that does not compile.
Commenting and style o [4 pts] Comments should be clearly written with correct grammar and spelling.
[5 pts] Indentation and general appearance should be consistent and make the code easy to read.
[3 pts] You should write a comment for each major piece of computation. For example, // Determine the health care plan o [3 pts] You should also write a comment at the top of your file with the following content:
/*
CS16000 Spring 2015
Project 2: Test Statistics
Description: */
[1 pt] The program should consist of one class, called ExamStatistics
[3 pts] The class should contain one static named constant field to hold the passing cutoff (i.e., 70 points).
[1 pt] Besides the named constant, the class should contain only the main method.
Note that your main method will likely need a "throws IOException" declaration (see p245 of the textbook).
Variables in the main method:
[4 pts] The main method should include variables called minScore, maxScore, sumScores, and averageScore. You should determine the appropriate types for those variables (some of them have multiple correct possibilities).
[1 pt] You should also have a String variable inFileName to store the file name received from the user. o [5 pts] You will need other variables as well. It is up to you to determine what variables you need and what types they should be. Think about the information that your program needs to store during its execution.
The main method should carry out the following tasks in this order: o Declare variables as needed o [2 pts] Declare and instantiate a Scanner object to read data from the console o [2 pts] Solicit the input file name from the user via the console with the message "Please enter the file name: "
[6 pts] While the given file name does not exist... (see p249 and following in the textbook)
Print out the message "File could not be opened. Please try again." o Solicit the input file name from the user via the console with the message "Please enter the file name: "
Note that at this point, you should have a File object for an existing input file. o [2 pts] Create a Scanner to read from the file.
[20 pts] Run a while loop to read the scores from the file. As you read them, you will also have to calculate...
the number of scores
the sum of the scores
the minimum score
the maximum score
the number of scores at or above 70
[3 pts] Compute the average score o [1 pt] Re-instantiate a Scanner to read from the file.
[6 pts] Loop over the scores in the file, counting how many are above the average score o [12 pts] Build a String that holds the message to print (i.e., a multi-line String). It should be formatted as described in previous sections.
[3 pts] Print the output to the console o [5 pts] Instantiate a PrintWriter object for a file ExamStatFile.txt o [8 pts] Write the output to the file
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started