Question: What am I doing wrong? I have my numbers.txt file on my desktop. run: This program calculates statistics on a file containing a series of

What am I doing wrong? I have my numbers.txt file on myWhat am I doing wrong? I have my numbers.txt file on my desktop. desktop. run: This program calculates statistics on a file containing a seriesof numbers Enter the file name: users eybaltazar desktop umbers.txt Exception inthread "main" java.io.FileNotFoundException: users eybaltazar\desktop umbers.txt (No such file or directory) atjava.io.FileInputStream.open(Native Method) | at java.io.FileInputStream.open(FileInputStream.java:195) at java.io.FileInputStream.(FileInputStream.java:138) at java.util.Scanner.(Scanner.java:611) at StatsDemo.main(StatsDemo.java:52) /Users/reybaltazar/Library/caches/NetBeans/8.2/executor-snippets/run.xml:53:Java returned: 1 BUILD FAILED (total time: 14 seconds) import java.io.File; 2

run: This program calculates statistics on a file containing a series of numbers Enter the file name: users eybaltazar desktop umbers.txt Exception in thread "main" java.io.FileNotFoundException: users eybaltazar\desktop umbers.txt (No such file or directory) at java.io.FileInputStream.open(Native Method) | at java.io.FileInputStream.open(FileInputStream.java:195) at java.io.FileInputStream.(FileInputStream.java:138) at java.util.Scanner.(Scanner.java:611) at StatsDemo.main(StatsDemo.java:52) /Users/reybaltazar/Library/caches/NetBeans/8.2/executor-snippets/run.xml:53: Java returned: 1 BUILD FAILED (total time: 14 seconds) import java.io.File; 2 import java.io.FileWriter; 3 import java.io.PrintWriter; 4 import java.util.Scanner; 5 6 // TASK #3 Add the file I/0 import statement here 7 8 ** 9 10 * This class reads numbers from a file, calculates the mean and standard 11 * deviation, and writes the results to a file. 12 13 */ 14 15 public class StatsDemo { 16 17 // TASK #3 Add the throws clause public static void main 18 19 public static void main(String[] args) throws Exception { 21 double sum = 0; // The sum of the numbers 22 23 int count = 0; // The number of numbers added 24 2 double mean = 0; // The average of the numbers 26 double stdDev = 0; // The standard deviation 28 29 String line; // to hold a line from the file 20 30 double difference; // The value and mean difference 31 32 33 // Create an object of type Scanner 34 35 Scanner keyboard = new Scanner(System.in); Scanner keyboard = new Scanner(System.in); 35 36 37 38 39 40 String filename; // The user input file name // Prompt the user and read in the file name System.out.println("This program calculates " + "statistics on a file " + "containing a series of numbers"); System.out.print("Enter the file name: "); filename = keyboard.nextLine(); // ADD LINES FOR TASK #4 HERE 43 44 45 46 47 48 49 50 51 52 53 54 55 56 // Create a File object passing it the filename File inputFile = new File(filename); // Create a Scanner object passing File object Scanner inputFileScanner = new Scanner(inputFile); // Perform a priming read to read the first line // of the file 58 59 60 61 62 63 64 65 66 67 68 69 // Loop until you are at the end of the file while (inputFileScanner. hasNext()) { // Read a new line from the file // Convert the line to a double value and add the line = inputFileScanner.nextLine(); double data = Double.parseDouble(line); // value to sum sum = sum + data; // Increment the counter count++; } // Close the input file inputFileScanner.close(); // Store the calculated mean mean = (double) sum / count; // ADD LINES FOR TASK #5 HERE // Reconnect File object passing it the // filename // Reconnect Scanner object passing 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 // File object inputFile = new File(filename); inputFileScanner = new Scanner(inputFile); // Reinitialize the sum of the numbers sum = 0; count = 0; // Reinitialize the number of numbers added // Perform a priming read to read the first line of // the file // Loop until you are at the end of the file while (inputFileScanner. hasNext()) { // Convert the line into a double value and line = inputFileScanner.nextLine(); line = inputFileScanner.nextLine(); double data = Double.parseDouble(line); // Add the square of the difference to the sum // subtract the mean difference = data - mean; // Add the square of the difference to the sum sum = sum + difference*difference; // Increment the counter count++; } 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 // Calculate standard deviation stdDev = Math.sqrt(sum / count); // Read a new line from the file // Close the input file inputFileScanner.close(); // Store the calculated standard deviation // ADD LINES FOR TASK #3 HERE // Create a Filewriter object using "Results.txt" FileWriter outputFileWriter = new FileWriter("Results.txt"); // Create a PrintWriter object passing the// FileWriter object Printwriter printwriter = new PrintWriter(outputFileWriter); // Print the results to the output file printWriter.write("Mean : " + mean); // Close the input file inputFileScanner.close(); // Store the calculated standard deviation // ADD LINES FOR TASK #3 HERE // Create a FileWriter object using "Results.txt" FileWriter outputFileWriter = new FileWriter("Results.txt"); 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 // Create a PrintWriter object passing the// FileWriter object PrintWriter printWriter = new PrintWriter(outputFileWriter); + stdDev); // Print the results to the output file printWriter.write("Mean : " + mean); printWriter.write(" Standart Deviation: // Close the output file printWriter.close(); outputFileWriter.close()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!