Question: Really Confused - Intro. JAVA class - ***Please help with the above before doing the below!*** Thank you!! Please answer if you have used Tony

 Really Confused - Intro. JAVA class - ***Please help with theabove before doing the below!*** Thank you!! Please answer if you haveused Tony Gaddis's Starting out with Java (from Control Structures through objects

Really Confused - Intro. JAVA class - ***Please help with the above before doing the below!*** Thank you!!

Please answer if you have used Tony Gaddis's Starting out with Java (from Control Structures through objects 6th ed.) and PLEASE DO NOT use content from beyond chapter 4. I've had this question answered before but I was only more confused b/c concepts from later chapters were used.

Two Files: StateDemo.java and Numbers.txt

Modify StatsDemo.java with the following tasks

1. Asked the user to read in a file of numbers. The user entered the file name.

2. The program calculated the sum, count, mean, minimal value and maximal value.

3. The program asked the user to enter a file name which will be used as an output file.

4. Instead of displaying the metrics to the screen the program will write four messages to the output file. - The messages will contain all the values of the metrics.

a. Hint i.e. if I was writing them to the screen they would be:

System.out.printf(the sum is = %10.2f , sum);

System.out.printf(the mean is = %10.2f , mean);

System.out.printf(the count is = %8d , count);

System.out.printf(the min is = %10.2f , min);

System.out.printf(the max is = %10.2f , max);

The program should have:

user friendly input and user friendly output

comments where needed and display the numbers with 2 decimal places

StateDemo.java

import java.util.Scanner; import java.io.*; /** This program reads a series of numbers from a file and accumulates their sum. */ public class StateDemo { public static void main(String[] args) throws IOException { double sum = 0.0; // Accumulator, initialized to 0 int count = 0; // Count, initialized to 0 double mean; // Mean of the series of numbers double min = 1e20; // Minimal value of the series numbers double max = -1e20; // Maximal value of the series numbers String filename; // Task 1: Ask user to enter a file name of the input file // Open the file for reading. File file = new File("Numbers.txt"); Scanner inputFile = new Scanner(file); // Read all of the values from the file // and calculate their total. while (inputFile.hasNext()) { // Read a value from the file. double number = inputFile.nextDouble(); // Add the number to sum. sum = sum + number; // Task 2: Modify the while loop to calculate stats metrics } // Close the file. inputFile.close(); // Task 3: Output all these metrics to a file specified by the user // Display the sum of the numbers. System.out.println("The sum of the numbers in " + "Numbers.txt is " + sum); } } 

Numbers.txt

8.7 7.9 3.0 9.2 12.6 

C'S 101 LAB4 CPS 101 LAB4 Task #1 Ask user to enter a file name of the input file 1. Copy StateDemo.java from Blackboard and Lab Objectives . Be able to write a while loop to calculate running total, download Numbers.txt. Create a Scanner object for keyboard input Ask user to enter the file name Change "Number.txt" to filename in File class count, average Be able to combine a while loop with if statement to get the minimal and maximal value . Be ableto read data from a file e Be able to write data to a file 2. 3. 4. Task #2 Modify the while loop to calculate all the statistical metrics 1. Increase count inside the while loop 2. Write an if statement to get the smaller value between min Introduction In this lab, we will be editing a statistic demo program. It reads data from Numbers.txt and calculate the sum of the numbers After that, it display the sum on the screen. The task of this lab is to calculate count, mcan, minimal and maximal value of these numbers from any input file user entered and output all the results to another file also specified by the user and number inside the while loop Write an if statement to get the larger value between max and number inside the while loop Calculate the mean outside the while loop 3. 4. Task #3 Output all these metrics to a file specified by the user 1. Get the output filename from user input and open it 2. 3. Hint: Use PrintWriter class to open the file Write all the metrics to the file Close the file and let user know the data is written to the

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!