Task #1 Writing Output to a File 1. Create a project using StatsDemoStarter.java from Module 12 and Numbers.txt from Module 12. (Optionally you could copy the starter code located at the bottom of this document). 2. First we will write output to a file: a. Create a FileWriter object passing it the filename Results.txt (Don't forget the needed import statement). b. Create a PrintWriter object passing it the FileWriter object. c. Since you are using a FileWriter object, add a throws clause to the main method header (throys JOExcention) The reason for this will be

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Code in JAVA language

Task #1 Writing Output to a File
1. Create a project using StatsDemoStarter.java from Module 12 and Numbers.txt
from Module 12. (Optionally you could copy the starter code located at the
bottom of this document).
2. First we will write output to a file:
a. Create a FileWriter object passing it the filename Results.txt (Don't
forget the needed import statement).
b. Create a PrintWriter object passing it the FileWriter object.
c. Since you are using a FileWriter object, add a throws clause to the
main method header. (throws IOException) The reason for this will be
explained in Module 13.
d. Print the mean and standard deviation to the output file using a three
decimal format, labeling each.
e. Close the output file.
3. Run your project. You will need to type in the filename Numbers.txt. You should
get no output to the console, but running the program will create a file called
Results.txt with your output. The output you should get at this point is: mean
0.000, standard deviation = 0.000. This is not the correct mean or standard
deviation for the data, but we will fix this in the next tasks.
Task #2 Calculating the Mean
1. Now we need to add lines to allow us to read from the input file and calculate the
mean.
a. Create a File object passing it the filename.(See slide 11)
b. Create a Scanner object passing it the File object. .(See slide 11)
2. Write a priming read to read the first line of the file.
3. Write a loop that continues until you are at the end of the file. (See slide 15)
4. The body of the loop will:
а.
convert the line into a double value and add the value to the accumulator
b. increment the counter
c. read a new line from the file
5. When the program exits the loop close the input file.
6. Calculate and store the mean. The mean is calculated by dividing the accumulator
by the counter.
Copyright © 2019 Pearson Education, Inc., Hoboken NJ
7. Compile, debug, and run. You should now get a mean of 77.444, but the standard
deviation will still be 0.000.
Transcribed Image Text:Task #1 Writing Output to a File 1. Create a project using StatsDemoStarter.java from Module 12 and Numbers.txt from Module 12. (Optionally you could copy the starter code located at the bottom of this document). 2. First we will write output to a file: a. Create a FileWriter object passing it the filename Results.txt (Don't forget the needed import statement). b. Create a PrintWriter object passing it the FileWriter object. c. Since you are using a FileWriter object, add a throws clause to the main method header. (throws IOException) The reason for this will be explained in Module 13. d. Print the mean and standard deviation to the output file using a three decimal format, labeling each. e. Close the output file. 3. Run your project. You will need to type in the filename Numbers.txt. You should get no output to the console, but running the program will create a file called Results.txt with your output. The output you should get at this point is: mean 0.000, standard deviation = 0.000. This is not the correct mean or standard deviation for the data, but we will fix this in the next tasks. Task #2 Calculating the Mean 1. Now we need to add lines to allow us to read from the input file and calculate the mean. a. Create a File object passing it the filename.(See slide 11) b. Create a Scanner object passing it the File object. .(See slide 11) 2. Write a priming read to read the first line of the file. 3. Write a loop that continues until you are at the end of the file. (See slide 15) 4. The body of the loop will: а. convert the line into a double value and add the value to the accumulator b. increment the counter c. read a new line from the file 5. When the program exits the loop close the input file. 6. Calculate and store the mean. The mean is calculated by dividing the accumulator by the counter. Copyright © 2019 Pearson Education, Inc., Hoboken NJ 7. Compile, debug, and run. You should now get a mean of 77.444, but the standard deviation will still be 0.000.
Task #3 Calculating the Standard Deviation
1. We need to reconnect to the file so we can start reading from the top again.
Create a Scanner object passing it the File object created in Task# 2.(See
slide 11)
а.
2. Reinitialize the sum and count t 0.
3. Write a priming read to read the first line of the file.
4. Write a loop that continues until you are at the end of the file.
5. The body of the loop will:
а.
convert the line into a double value and subtract the mean, store the result
in difference
b. add the square of the difference to the accumulator
c. increment the counter
d. read a newline from the file.
6. When the program exits the loop close the input file.
7. The variance is calculated by dividing the accumulator (sum of the squares of the
difference) by the counter. Calculate the standard deviation by taking the square
root of the variance (Use the Math.sgrt method to take the square root).
8. Run your project. You should get a mean of 77.444 and standard
deviation of 10.021.
Transcribed Image Text:Task #3 Calculating the Standard Deviation 1. We need to reconnect to the file so we can start reading from the top again. Create a Scanner object passing it the File object created in Task# 2.(See slide 11) а. 2. Reinitialize the sum and count t 0. 3. Write a priming read to read the first line of the file. 4. Write a loop that continues until you are at the end of the file. 5. The body of the loop will: а. convert the line into a double value and subtract the mean, store the result in difference b. add the square of the difference to the accumulator c. increment the counter d. read a newline from the file. 6. When the program exits the loop close the input file. 7. The variance is calculated by dividing the accumulator (sum of the squares of the difference) by the counter. Calculate the standard deviation by taking the square root of the variance (Use the Math.sgrt method to take the square root). 8. Run your project. You should get a mean of 77.444 and standard deviation of 10.021.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 4 images

Blurred answer
Knowledge Booster
Files and Directory
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education