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
Write a recursive function that calculates if two binary trees are similar?
ahrayia [7]

Answer:

bool identicaltrees(Node* root1,Node* root2)//function of type boolean true if idenctical false if not.

{

   if(root1==NULL&&root2==NULL)//both trees are null means identical.

   return true;

   if(roo1 && root2)

   {

       if(root1->data==root2->data)//condition for recursive call..

       {

           return (identicaltrees(root1->left,root2->right)&&identicaltrees(root1->right&&root2->right);

       }

   }

   else

   return false;

}

Explanation:

In this function it of type boolean returns true if both the trees are identical return false if not.First we are checking root node of both the trees if both are null then they are identical returning true.

If both root nodes are not null then checking their data.If data is same then recursively traversing on both trees and checking both trees.

else returning false.

5 0
3 years ago
Ladders are a fundamental piece of equipment on construction sites and employers are expected to ensure that workers follow safe
Ede4ka [16]
That statement is true.

Ladders commonly used to do a couple of construction activities in a higher region of a building or area.
If this equipment is not used properly, it could potentially caused  fatal accidents for the people on the site
6 0
3 years ago
Write a program great_circle.python that takes four float arguments x1 y1 x2 y2
svlad2 [7]

Answer:

897893+ 892e98374))8qwye932__8730140923(7834983(8974+9)9903)

Explanation:

IT IS SIMPLE MY FRIEND

spanish conquistadors, who were primarily poor nobles from the impoverished west and south of Spain, were able to conquer the huge empires of the New World with the help of superior military technology, disease (which weakened indigenous resistance), and military tactics including surprise attacks and powerful and there were no strangers to love and they knew the rules and so did i they just wanted to tell people how the were feeling and they wanted someone to understand so they were never gonna give you up and they were never gonna let them down and they were never gonna turn around and hurt other people in the army they were never gonna make the soldiers cry and they never were going to say goodbye but the years stop comming and they dont stop comming head to the rules gotta keep the groud running but Remember those walls I built Well, baby, they're tumbling down And they didn't even put up a fight They didn't even make a sound I found a way to let you win But I never really had a doubt Standing in the light of your halo I got my angel now It's like I've been awakened Every rule I had you breaking It's the risk that I'm taking I ain't never gonna shut you out Everywhere I'm looking now I'm surrounded by your embrace BabPatrician. Patricians were considered the upper-class in early Roman society. They controlled the best land and made up the majority of the Roman senate.y, I can see your halo You know you're my saving grace You're everything I need and morei t's written all over your face Baby, I can feel your halo Pray it won't fade away  Hit me like a ray of sun Burning through my darkest night I'm boutta' pop,  you know I'm boutta' blow up Only need these hands I don't need no  pole Once I get a grip, I might blast yo  dome up Like I'm Bakugo, turn they soul to  smokei 'm boutta' pop,  you know I'm boutta' blow up Only need these hands, I don't need no ' pole Once I get a grip, I might blast yo dome up Why you packin', you ain't bout' that action I'll blow her back in Why you mad but not attackin' boy I'll send you packin' I'm the best, no doubt about it Competition live without it You just mad cause I'm too rowdy get back I'm really bout it Head down on the ground, you don't want these hands around you Nitroglycerin I'm sweatin', blastin' off I'm bound to Rushin', there ain't no hiding yous a  if you down to If you try to hide you gon' be begging once I've found you I'm the best, ain't no hero but always been vet if you got an issue, AP shots up to yo neck I don't give a  about no one, I'll say it no regrets I'm only here for me, I'm at the top and you'll respect Grenadier bracers on my wrist, I'm about to pull the pin Come at me with all your might or I'ma melt off all your skin Howitzer impact  ,  I told you I'ma win get back before I blast, I said I'll do it again wit' a grin Like I'm Bakugo, turn they soul to ' smoke I'm boutta' pop,  you know I'm boutta' blow up Only need these hands I don't need no  pole Once I get a grip, I might blast yo  dome up and  I want Think I'm addicted to your light  swore I'd never fall again But this don't even feel like falling Gravity can't forget To pull me back to the ground again Patric Patrician. Patricians were considered the upper-class in early Roman society. They controlled the best land and made up the majority of the Roman senate.ian. sorry teacher but i am gay They also needed to pack it box it flip it top it wit a bowtie ribbion stop it because there dogs were eating all the rainbow cookies and pies were filying through the roof. Patricians were considered the upper-class in early Roman society. They controlled the best land and made up the majority of the Roman senate.

6 0
3 years ago
Carl wants to add a new slide to his PowerPoint presentation. Which option should he use?
djverab [1.8K]

Answer:

C on edg

Explanation:

I just took the review

8 0
3 years ago
Read 2 more answers
Generally, what is the term for storage locations in a processor?
oksano4ka [1.4K]

Answer: Registers

Explanation:

Registers are small storage locations identified by different types of registers. The function of the register is to provide data for immediate processing to the CPU. These registers hold data temporarily and provide easy access of data to the processor.

6 0
3 years ago
Other questions:
  • What are issues to consider when deciding to build software in-house or purchase commercial off-the-shelf software (cots)?
    14·1 answer
  • The __________ vulnerability assessment is a process designed to find and document selected vulnerabilities that are likely to b
    15·1 answer
  • . What is automated testing?
    10·1 answer
  • What is transaction model?
    9·2 answers
  • What is the problem with the code snippet below? public class Test { public static void main(String[] args) { System.out.println
    6·1 answer
  • Write a program that echos back any inputted integer greater than 1, and exits when a 0 is entered. Your program should use a co
    11·1 answer
  • A(n) ____ consists of a series of related instructions, organized for a common purpose, that tells the computer what tasks to pe
    6·1 answer
  • We can improve our knowledge and skills on animals and fish raising with the use of internet​
    15·1 answer
  • Which of these are examples of an access control system? Check all that apply.
    7·1 answer
  • A Python file that contains variables and functions and can be used in other programs is called a
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!