1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Anika [276]
3 years ago
9

Write a program that will ask for the user to input a filename of a text file that contains an unknown number of integers. And a

lso an output filename to display results. You will read all of the integers from the input file, and store them in an array. (You may need to read all the values in the file once just to get the total count) Using this array you will find the max number, min number, average value, and standard deviation. These results will be reported to both the screen and placed into the output file that the user choose. Output to screen and file could look like this: Read from file: 12 values Maximum value
Computers and Technology
1 answer:
Ratling [72]3 years ago
7 0

Answer: Provided in the explanation section

Explanation:

Code provided below in a well arranged format

inputNos.txt

70

95

62

88

90

85

75

79

50

80

82

88

81

93

75

78

62

55

89

94

73

82

___________________

StandardDev.java

import java.io.File;

import java.io.FileNotFoundException;

import java.util.Scanner;

public class StandardDev {

public static void main(String[] args) {

//Declaring variables

String filename;

int count = 0, i = 0;

Scanner sc1 = null;

int min, max;

double mean, stdDev;

int nos[] = null;

/*

* Creating an Scanner class object which is used to get the inputs

* entered by the user

*/

Scanner sc = new Scanner(System.in);

//Getting the input entered by the user

System.out.print("Enter the name of the filename :");

filename = sc.next();

try {

//Opening the file

sc1 = new Scanner(new File(filename));

//counting no of numbers in the file

while (sc1.hasNext()) {

sc1.nextInt();

count++;

}

sc1.close();

sc1 = new Scanner(new File(filename));

//Creating an Integer based on the Count

nos = new int[count];

//Populating the values into an array

while (sc1.hasNext()) {

nos[i] = sc1.nextInt();

i++;

}

sc1.close();

//calling the methods

min = findMinimum(nos);

max = findMaximum(nos);

mean = calMean(nos);

stdDev = calStandardDev(nos, mean);

//Displaying the output

System.out.println("Read from file :" + count + " values");

System.out.println("The Minimum Number is :" + min);

System.out.println("The Maximum Number is :" + max);

System.out.printf("The Mean is :%.2f\n", mean);

System.out.printf("The Standard Deviation is :%.2f\n", stdDev);

} catch (FileNotFoundException e) {

e.printStackTrace();

}

}

//This method will calculate the standard deviation

private static double calStandardDev(int[] nos, double mean) {

//Declaring local variables

double standard_deviation = 0.0, variance = 0.0, sum_of_squares = 0.0;

/* This loop Calculating the sum of

* square of eeach element in the array

*/

for (int i = 0; i < nos.length; i++) {

/* Calculating the sum of square of

* each element in the array    

*/

sum_of_squares += Math.pow((nos[i] - mean), 2);

}

//calculating the variance of an array

variance = ((double) sum_of_squares / (nos.length - 1));

//calculating the standard deviation of an array

standard_deviation = Math.sqrt(variance);

return standard_deviation;

}

//This method will calculate the mean

private static double calMean(int[] nos) {

double mean = 0.0, tot = 0.0;

// This for loop will find the minimum and maximum of an array

for (int i = 0; i < nos.length; i++) {

// Calculating the sum of all the elements in the array

tot += nos[i];

}

mean = tot / nos.length;

return mean;

}

//This method will find the Minimum element in the array

private static int findMinimum(int[] nos) {

int min = nos[0];

// This for loop will find the minimum and maximum of an array

for (int i = 0; i < nos.length; i++) {

// Finding minimum element

if (nos[i] < min)

min = nos[i];

}

return min;

}

//This method will find the Maximum element in the array

private static int findMaximum(int[] nos) {

int max = nos[0];

// This for loop will find the minimum and maximum of an array

for (int i = 0; i < nos.length; i++) {

// Finding minimum element

if (nos[i] > max)

max = nos[i];

}

return max;

}

}

_____________________

Output:

Enter the name of the filename :inputNos.txt

Read from file :22 values

The Minimum Number is :50

The Maximum Number is :95

The Mean is :78.45

The Standard Deviation is :12.45

cheers i hope this helped !!!

You might be interested in
Marlene is using context clues to better understand the book she is reading. After reading around unfamiliar words and checking
Zigmanuir [339]

Answer: The correct answer is to look up the unfamiliar words in a dictionary or online.

Explanation: When using context clues to better understand reading, Marlene will first read around the unfamiliar words, looking for clues before and after the unfamiliar words. If she still does not know the meaning of an unfamiliar word her next step is to look up the word in a dictionary or online.

5 0
3 years ago
Read 2 more answers
In a _______ format, the date line and the signature block are centered.
kakasveta [241]
The answer to this is C. Modified block
6 0
3 years ago
To add text to a slide when using presentation software, you need to add a text box. To add a text box, click the Text Box butto
Ket [755]
Its A because u can add them using the format tab
3 0
3 years ago
Read 2 more answers
12. What was the trade Howard offered to Death?​
Pachacha [2.7K]

Answer:

His life

Explanation:

5 0
2 years ago
Which of the following peripheral devices can be used for both input and output? mouse printer CPU touch screen on a tablet comp
LenaWriter [7]
Touch Screen, it provides both visual output and touch input.                                                
3 0
3 years ago
Read 2 more answers
Other questions:
  • How do you change the username on here?
    14·1 answer
  • Help with some questions. Thank you!
    14·1 answer
  • This diagram shows a number of computing devices connected to the Internet with each line representing a direct connection.
    11·1 answer
  • Cual es la herramienta de google que funciona como oficce ?
    11·1 answer
  • What are the two main parts of system unit hardware?
    8·1 answer
  • What department is cyber security
    6·2 answers
  • What is computer system<br>explain the role of bank in computer<br>​
    15·2 answers
  • Select all that apply.
    12·1 answer
  • What does a blinking yelow light mean on a phillips sonicare toothbrush
    9·1 answer
  • A block signature indicating that a text message was typed on a mobile device is an example of ____________.
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!