The standard deviation of a list of numbers is a measure of

The standard deviation of a list of numbers is a measure of how much the numbers deviate from the average. If the standard deviation is small, the numbers are clustered close to the average. If the standard deviation is large, the numbers are scattered far from the average. The standard deviation of a list of numbers n1, n2, n3, and so forth is defined as the square root of the average of the following numbers:

(n1 - a)^2, (n2 - a)^2, (n3 - a)^2, and so forth.

The number a is the average of the numbers n1, n2, n3, and so forth. Define a static method that takes a partially filled array of numbers as its argument and returns the standard deviation of the numbers in the partially filled array. Since a partially filled array requires two arguments, the method will actually have two formal parameters, an array parameter and a formal parameter of type int that gives the number of array positions used. The numbers in the array will be of type double. Write a suitable test program for your method. (JCreator Java)

Solution

import java.util.Scanner;

public class Deviations

{

public static double standard(double[] a, int n)

{

double average = computeAverage(a, n);

double total = 0;

for(int i = 0; i < n; i++)

{

double[] all = Math.pow(a[i]-average, 2);

total = total + all;

double total2 = total/n;

double[] all2 = Math.sqrt(total2);

}

}

public static int fillTheArray(double[] a)

{

System.out.println(\"Enter up to \" + a.length + \" nonnegative numbers.\");

System.out.println(\"Enter a -1 when you are finished.\");

Scanner keyboard = new Scanner(System.in);

double next;

int i = 0;

next = keyboard.nextDouble();

while((next >= 0)&&(i < a.length))

{

a[i] = next;

i++;

next = keyboard.nextDouble();

}

if(next>=0)

{

System.out.println(\"Could only read in \" + a.length + \" input values.\");

}

return i;

}

public static double computeAverage(double[] a, int n)

{

double average = 0;

for(int i = 0; i < n; i++)

average = average + a[i];

if(n > 0)

{

return (average/n);

}

else

{

System.out.println(\"ERROR: Can\'t average 0 numbers.\");

return 0;

}

}

}

Driver program

import java.util.Scanner;

public class DeviationsDemo

{

public static void main(String[] args)

{

Deviations deed = new Deviations();

double[] a = new double[15];

int n = 0;

Scanner keyboard = new Scanner(System.in);

n = deed.fillTheArray(a);

deed.standard(a, n);

}

}

The standard deviation of a list of numbers is a measure of how much the numbers deviate from the average. If the standard deviation is small, the numbers are c
The standard deviation of a list of numbers is a measure of how much the numbers deviate from the average. If the standard deviation is small, the numbers are c
The standard deviation of a list of numbers is a measure of how much the numbers deviate from the average. If the standard deviation is small, the numbers are c

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site