Using the knowledge of computational language in JAVA it is possible to write a code that Validate that the following code, which adds the methods var() and stddev() to Accumulator, computes both the mean and variance of the numbers presented as arguments to addDataValue()
<h3>Writting the code:</h3>
<em>import java.util.*;</em>
<em>public class </em><em>Accumulator </em><em>{ </em>
<em>private static double m; </em>
<em>private static double v; </em>
<em>private static double st; </em>
<em>private static double s[]=new double[5]; </em>
<em>private static int N;</em>
<em>private static int count =0;</em>
<em>public static void main(String[] args) {</em>
<em>// TODO Auto-</em><em>generated </em><em>method stub</em>
<em>Random r = new Random();</em>
<em>System.out.println("hello world");</em>
<em>for(int i=0;i<5;i++) {</em>
<em> double randomvalue = r.nextDouble();</em>
<em>addDataValue(randomvalue);</em>
<em>}</em>
<em>for(int i=0;i<s.length;i++) {</em>
<em> System.out.println("dataValue:"+s[i]);</em>
<em>} </em>
<em>mean();</em>
<em>System.out.println("mean:"+m);</em>
<em>var();</em>
<em>System.out.println("variance:"+v);</em>
<em>stddev();</em>
<em>System.out.println("standard deviation:"+st);</em>
<em>}</em>
<em>public static void </em><em>addDataValue</em><em>(double value) { // addes data values to array</em>
<em> s[count]=value;</em>
<em> count++;</em>
<em> }</em>
<em>public static double mean() { // returns mean</em>
<em>double sum=0.0;</em>
<em>for(int i=0;i<s.length;i++) {</em>
<em> sum+=s[i];</em>
<em>}</em>
<em>m = sum/s.length;</em>
<em> return m;</em>
<em>} </em>
<em>public </em><em>static </em><em>double var() { //returns variance</em>
<em>double mm = mean();</em>
<em> double t = 0;</em>
<em> for(int i=0;i<s.length;i++) {</em>
<em> t+= (s[i]-mm)*(s[i]-mm);</em>
<em>} </em>
<em> v= t/(s.length-1);</em>
<em> return v; </em>
<em>}</em>
<em>public static double </em><em>stddev</em><em>() { // returnsn the stardard deviation </em>
<em>st= Math.sqrt(var());</em>
<em>return st;</em>
<em>}</em>
<em>}</em>
See more about JAVA at brainly.com/question/12975450
#SPJ1