Results 1 to 8 of 8
 05132012, 03:24 PM #1Member
 Join Date
 May 2012
 Posts
 4
 Rep Power
 0
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("$" + (nextSalesaverageSales)
+ "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();
}
}
 05132012, 04:49 PM #2
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.
 05132012, 05:03 PM #3
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.
 05132012, 05:10 PM #4Member
 Join Date
 May 2012
 Posts
 4
 Rep Power
 0
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 = (averageSalesteam[i].getSales());
sum = sum + diff*diff;
}
double variance = sum / ( numberOfAssociates1 );
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)
 05132012, 05:12 PM #5
Re: How would I add standard deviation to my program? Please help.
I get an error messageIf you don't understand my response, don't ignore it, ask a question.
 05132012, 05:15 PM #6Member
 Join Date
 May 2012
 Posts
 4
 Rep Power
 0
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
 05132012, 05:25 PM #7Member
 Join Date
 May 2012
 Posts
 4
 Rep Power
 0
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
 05132012, 05:45 PM #8
Similar Threads

standard deviation in java
By noobplus in forum New To JavaReplies: 1Last Post: 03172012, 06:22 PM 
Computing standard deviation using public static classes to call from another class
By exeye0h in forum New To JavaReplies: 15Last Post: 02132012, 10:00 PM 
standard deviation error
By rochla16 in forum New To JavaReplies: 2Last Post: 05032011, 05:43 AM 
standard deviation calculation
By rochla16 in forum New To JavaReplies: 5Last Post: 04282011, 08:27 PM 
standard deviation and mean for an array
By peterdfl in forum New To JavaReplies: 3Last Post: 05292008, 05:09 AM
Bookmarks