Results 1 to 8 of 8
  1. #1
    WilsonGTI45 is offline Member
    Join Date
    May 2012
    Posts
    4
    Rep Power
    0

    Default How would I add standard deviation to my program? Please help.

    New to Java and having trouble adding standard deviation to my program. Please help, it would be greatly appreciated!

    package sales.report;

    import java.util.Scanner;
    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    /**
    *
    * @author MILFHUNTER
    */
    public class SalesReporter {
    private double highestSales;
    private double averageSales;
    private SalesAssociate[] team;

    private int numberOfAssociates;

    public void getData()
    {
    Scanner keyboard = new Scanner(System.in);
    System.out.println("Enter number of sales associates:");
    numberOfAssociates = keyboard.nextInt();
    team = new SalesAssociate[numberOfAssociates +1 ];

    for (int i = 1; i <= numberOfAssociates; i++)
    {
    team[i] = new SalesAssociate();
    System.out.println("Enter data for associate " + i);
    team[i].readInput();
    System.out.println();
    }
    }
    public void computeStats()
    {
    double nextSales = team[1].getSales();
    highestSales = nextSales;
    double sum = nextSales;
    for (int i = 2; i <= numberOfAssociates; i++)
    {
    nextSales = team[i].getSales();
    sum = sum + nextSales;
    if (nextSales > highestSales)
    highestSales = nextSales;
    }
    averageSales = sum / numberOfAssociates;
    }
    public void displayResults()
    {
    System.out.println("Average sales per associate is $" +
    averageSales);
    System.out.println("The highest sales figure is $" +
    highestSales);
    System.out.println();
    System.out.println("The following had the highest sales");
    for (int i = 1; i <= numberOfAssociates; i++)
    {
    double nextSales = team[i].getSales();
    if (nextSales == highestSales)
    {
    team[i].writeOutput();
    System.out.println("$" + (nextSales-averageSales)
    + "above the average.");
    System.out.println();

    }
    }
    System.out.println("The rest performed as follows");
    for (int i = 1; i <= numberOfAssociates; i++)
    {
    double nextSales = team[i].getSales();
    if (team[i].getSales() != highestSales)
    {
    team[i].writeOutput();
    if (nextSales >= averageSales)
    System.out.println("$" + (nextSales-
    averageSales) + "above the average.");
    else
    System.out.println("$" + (averageSales -
    nextSales) + "below the average.");
    System.out.println();

    }
    }
    }
    public static void main(String[] args)
    {
    SalesReporter clerk = new SalesReporter();
    clerk.getData();
    clerk.computeStats();
    clerk.displayResults();

    }
    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default Re: How would I add standard deviation to my program? Please help.

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: How would I add standard deviation to my program? Please help.

    Can you explain where your formula is for computing the desired value?
    If you don't understand my response, don't ignore it, ask a question.

  4. #4
    WilsonGTI45 is offline Member
    Join Date
    May 2012
    Posts
    4
    Rep Power
    0

    Default Re: How would I add standard deviation to my program? Please help.

    public void computeStats()
    {
    double nextSales = team[1].getSales();
    highestSales = nextSales;
    double sum = nextSales;
    for (int i = 2; i <= numberOfAssociates; i++)
    {
    nextSales = team[i].getSales();
    sum = sum + nextSales;
    if (nextSales > highestSales)
    highestSales = nextSales;
    }
    averageSales = sum / numberOfAssociates;
    sum = 0;
    for ( int i = 1; i<= numberOfAssociates; i++)
    {double diff = (averageSales-team[i].getSales());
    sum = sum + diff*diff;
    }
    double variance = sum / ( numberOfAssociates-1 );
    stdDev = sqrt (variance)

    So I have worked on it some more in this is what I have...I get an error message(erroneous symbol) for stdDev = sqrt (variance)

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: How would I add standard deviation to my program? Please help.

    I get an error message
    Please post the full text of the error message.
    If you don't understand my response, don't ignore it, ask a question.

  6. #6
    WilsonGTI45 is offline Member
    Join Date
    May 2012
    Posts
    4
    Rep Power
    0

    Default Re: How would I add standard deviation to my program? Please help.

    Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: sqrt
    at sales.report.SalesReporter.computeStats(SalesRepor ter.java:59)
    at sales.report.SalesReporter.main(SalesReporter.java :104)
    Java Result: 1

  7. #7
    WilsonGTI45 is offline Member
    Join Date
    May 2012
    Posts
    4
    Rep Power
    0

    Default Re: How would I add standard deviation to my program? Please help.

    Ok I fixed that...

    should be Math.sqrt instead of sqrt

    Having trouble displaying in results now when i run the program

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default Re: How would I add standard deviation to my program? Please help.

    WilsonGTI45, I posted three links for you. I expect you to go through them.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. standard deviation in java
    By noobplus in forum New To Java
    Replies: 1
    Last Post: 03-17-2012, 06:22 PM
  2. Replies: 15
    Last Post: 02-13-2012, 10:00 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

Tags for this Thread

Posting Permissions

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