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]
4 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]4 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
Which statements about viruses are true? select the four statements that are true. select the four statements that are true. all
navik [9.2K]
<span>A) All viral genomes contain both DNA and RNA. FALSE. Viruses contain the smallest necessary amount of genetic information packaged in a capsule composed of proteins. Containing both DNA and RNA would be a redundancy that would unnecessarily increase the size of the virus and make it more difficult for the virus to penetrate a cell. B) A retrovirus contains RNA. TRUE. By definition a retrovirus contains single-stranded positive-sense RNA instead of DNA. C) HIV contains two identical strands of DNA. FALSE. HIV is a retrovirus and, therefore, contains RNA instead of DNA. D) HIV contains reverse transcriptase. TRUE. HIV is a retrovirus that contains an RNA genome. All retroviruses require reverse transcriptase to convert their genome from RNA to DNA once the virus has been entered the cell. E) The capsid enters the host cell if the virus is enveloped. TRUE. Viruses are to large to enter a cell by passive diffusion or active transport. The only remaining major form a transport into the cell is endocytosis, or being enveloped. F) All RNA-containing viruses are retroviruses. FALSE. By definition a retrovirus contains single-stranded positive-sense RNA. Viruses can contain RNA in other forms (ie double-stranded) and would, therefore, not be considered a retrovirus. G) Enveloped viruses bud from the host cell. TRUE. Viruses are to large to enter a cell by passive diffusion or active transport. The only remaining major form a transport into the cell is exocytosis. For a virus to exit the host cell and infect other cells, they must exit by exocytosis, or budding.</span>
4 0
3 years ago
Anyone here play sims 4 and know how to help me with his last exception file?
zysi [14]

Answer:

Explanation:

What game is this

3 0
3 years ago
Jason Diaz is a financial advisor who works in an open office with coworkers nearby. Jason advises clients both in person and ov
Elanso [62]

Answer:

There is a need for a microphone and a speaker in the form of a headset for privacy, also, the conventional keyboard and monitor screen. For information security, a configured firewall is recommended to prevent hacking.

Explanation:

Input and output devices are tools used by an operator of a computer device to give instructions and monitor results respectively.

Jason would need a headset, which has a speaker for hearing and a microphone for speaking to the client on a video conference call. These I/O devices are readily available on some personal computers. Every computer system has a keyboard and a monitor, this is also useful for Jason for communicating with his client.

7 0
3 years ago
Addressing is an added feature on the Internet, and is not required for proper operation of the Internet, as packet switching is
Irina18 [472]

Answer:

True

Explanation:

The statement is true. Packet switching is a method that groups the data and transmit it over the digital network. It is basis for communication in the computer. When the two host decides to communicate the network creates a control function and data is transmitted. Addressing is an added and is not mandatory for the operations of the internet as packet switching.

7 0
3 years ago
What notation requires parentheses in order to correctly define the order of computation? Group of answer choices prefix notatio
Alexxx [7]

Answer:

The correct answer is Option B (infix notation).

Explanation:

  • The conventional format of logical as well as mathematical formulas where operators write the precise manner of infix amongst variables or the inputs is considered as Infix notation.
  • Computer systems cannot easily be scanned like prefix and post-fix kind of notation, nevertheless owing to its convenience it has been used throughout numerous computer programs.

All other given options aren't related to the given scenario. So the above is the correct one.

4 0
3 years ago
Other questions:
  • Jill edited James's document using Track Changes. James agrees with all of the edits and wants to incorporate them into his text
    6·1 answer
  • A personal business letter is a letter that is ____.
    13·1 answer
  • To what extent are the following computer systems instances of artificial intelligence:
    14·1 answer
  • Andrew has data in cell E14 and the cell should be blank. Andrew should _____.
    15·2 answers
  • Which of the following statements is false ^^^^^Please Help^^^^^^
    10·1 answer
  • It is perhaps not surprising that Etsy was an early adopter of DevOps. It is a relatively small company, with a start-up culture
    7·1 answer
  • public class Ex0506 { public static void main (String args[]) { int x = 2; while (x &lt; 10) { if (x % 2 == 0) x+=3; else x+=2;
    15·1 answer
  • What is the benifet of the manager feature
    13·1 answer
  • To keep files organized, related documents are often stored in ____ (also called directories) located on the storage medium.
    11·1 answer
  • A(n) ___________________________ is a pl/sql block that executes in place of a dml action on a database view.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!