Results 1 to 3 of 3
  1. #1
    dustinnettles is offline Member
    Join Date
    Nov 2012
    Posts
    1
    Rep Power
    0

    Default 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.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);
    		  
    		  }
    }

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default 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.
    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.)

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default Re: Standard deviation project

    Quote Originally Posted by pbrockway2 View Post
    (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
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Replies: 7
    Last Post: 05-13-2012, 05:45 PM
  2. standard deviation in java
    By noobplus in forum New To Java
    Replies: 1
    Last Post: 03-17-2012, 06:22 PM
  3. standard deviation error
    By rochla16 in forum New To Java
    Replies: 2
    Last Post: 05-03-2011, 05:43 AM
  4. standard deviation calculation
    By rochla16 in forum New To Java
    Replies: 5
    Last Post: 04-28-2011, 08:27 PM
  5. standard deviation and mean for an array
    By peterdfl in forum New To Java
    Replies: 3
    Last Post: 05-29-2008, 05:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •