Question: Implement a Java class Stats to calculate the mean, median, empirical mode, population variance, and sample variance as specified below. package assignment2; public class Stats

Implement a Java class Stats to calculate the mean, median, empirical mode, population variance, and sample variance as specified below.
package assignment2;
public class Stats {
// mean
public static double mean(double[] x) {
}
// median
public static double median(double[] x) {
}
// empirical mode
public static double mode(double[] x) {
}
// population variance
public static double var(double[] x) {
}
// sample variance
public static double s2(double[] x) {
}
public static void main(String[] args) {
double[] x = {3, -2, 5, 0, 9, 3, 2, 1};
System.out.println("mean = " + mean(x));
System.out.println("median = " + median(x));
System.out.println("empirical mode = " + mode(x));
System.out.println("var = " + var(x));
System.out.println("sample var = " + s2(x));
} }
A sample test program is provided in the main method, which will produce the output:
mean = 2.625
median = 2.5
empirical mode = 2.25
var = 9.734375
sample var = 11.125

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!