# Standard deviation project

• 11-27-2012, 11:54 PM
dustinnettles
Standard deviation project
Write a program to input up to 100 percentage scores and output 'A', 'B', 'C', 'D' or 'F' based on the standard deviation. A is 1½ standard deviations above the mean and better, B is ½ standard deviations above to 1½ standard deviations above the mean, C is anything from ½ a standard deviation above the mean to ½ a standard deviation below, D is 1½ standard deviations below the mean to ½ a standard deviation below the mean, and F is more than 1½ standard deviations below the mean. Enter a negative grade to quit.

this is what I have so far any help would be greatly appreciated.

I am hung up trying to make a loop so that it will only calculate with positive answers and when a negative is inserted it will stop.

Code:

import java.util.*;

public class StandardDeviation{
public double findMean(int array[]){
double total = 0;
for(int i = 0; i < array.length; i++){
total = total + array[i];
}
double mean = total/array.length;
return mean;
}
public void findStandardDeviation(int array[]){
double mean = findMean(array);
System.out.println("Mean is: "+mean);
double d1 = 0;
double d2 = 0;
double sum = 0;
for(int i = 0; i < array.length; i++){
d2 = (mean - array[i])*(mean - array[i]);
d1 = d2 + d1;
}
System.out.println("Standard Deviation: " + Math.sqrt((d1/(array.length-1))));
}

public static void main(String args[]){
Scanner input =new Scanner(System.in);

System.out.println("Enter Array Elements: ");
int array[] = new int[100];
for(int i=0;i<array.length;i++){
array[i]=input.nextInt();

}
StandardDeviation sd = new StandardDeviation();
sd.findStandardDeviation(array);

}
}

• 11-28-2012, 06:56 AM
pbrockway2
Re: Standard deviation project
Quote:

I am hung up trying to make a loop so that it will only calculate with positive answers and when a negative is inserted it will stop.
The simple answer is that you can use an if statement to check what was entered and, if it is negative, then break out of the loop.

Notice, though, that the array will contain a whole bunch of zeros at the end. And this is no good because zero is a valid data value. So what you are going to have to do is fill these unused array slots with some negative value.

Even once you have done that array.length has nothing to do with the number of scores that were entered. Again because of the unused slots at the end. You may find yourself having to implement a findCount() method in the StandardDeviation class so that the other two methods can use this value. (There is also a straight forward way of calculating the standard deviation with "one sweep" through the data - which is how calculators do it, for instance - which you might want to investigate.)
• 11-28-2012, 08:35 AM
JosAH
Re: Standard deviation project
Quote:

Originally Posted by pbrockway2
(There is also a straight forward way of calculating the standard deviation with "one sweep" through the data - which is how calculators do it, for instance - which you might want to investigate.)

... and those old calculators don't even have enough memory for huge arrays, so they don't use them ...

kind regards,

Jos