Results 1 to 3 of 3
Thread: Standard deviation project
 11272012, 11:54 PM #1Member
 Join Date
 Nov 2012
 Posts
 1
 Rep Power
 0
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.
Java 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.length1)))); } 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); } }
 11282012, 06:56 AM #2Moderator
 Join Date
 Feb 2009
 Location
 New Zealand
 Posts
 4,684
 Rep Power
 13
Re: Standard deviation project
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.
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.)
 11282012, 08:35 AM #3
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 13,935
 Blog Entries
 7
 Rep Power
 22
Similar Threads

How would I add standard deviation to my program? Please help.
By WilsonGTI45 in forum New To JavaReplies: 7Last Post: 05132012, 04:45 PM 
standard deviation in java
By noobplus in forum New To JavaReplies: 1Last Post: 03172012, 06:22 PM 
standard deviation error
By rochla16 in forum New To JavaReplies: 2Last Post: 05032011, 04:43 AM 
standard deviation calculation
By rochla16 in forum New To JavaReplies: 5Last Post: 04282011, 07:27 PM 
standard deviation and mean for an array
By peterdfl in forum New To JavaReplies: 3Last Post: 05292008, 04:09 AM
Bookmarks