Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

INTRO. JAVA CLASS - ****Is this correct?****** If it is, why is whenever I enter an input filename, NetBeans IDE 8.2 throws an exception? import

INTRO. JAVA CLASS - ****Is this correct?****** If it is, why is whenever I enter an input filename, NetBeans IDE 8.2 throws an exception?

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 Scanner keyboard = new Scanner(System.in); System.out.println("Enter the input filename: "); filename = keyboard.nextLine(); // Open the file for reading. File file = new File(filename); 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 //Count the numbers. count += 1; //Find the min value. if(min > number) { min = number; } //Find the max value. if(max

outputFile.printf("The sum is = %10.2f ",sum); outputFile.printf("The mean is = %10.2f ",mean); outputFile.printf("The count is = %10d ",count); outputFile.printf("The min is = %10.2f ",min); outputFile.printf("The max is = %10.2f ",max); outputFile.close();

// Display the sum of the numbers. System.out.println("The sum of the numbers in " + "Numbers.txt is " + sum); } }image text in transcribedimage text in transcribedimage text in transcribed

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

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

Building Database Driven Catalogs

Authors: Sherif Danish

1st Edition

0070153078, 978-0070153073

More Books

Students also viewed these Databases questions

Question

2. What kind of team is it?

Answered: 1 week ago

Question

=+j Identify the challenges of training an international workforce.

Answered: 1 week ago