Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Your software company has been requested to provide a prototype program performi

ID: 3801759 • Letter: Y

Question

Your software company has been requested to provide a prototype program performing the simple statistical evaluations. You will need to implement a main program that reads the values into the array (or you could write another method to read them in), then call each of the various methods that you will convert from your previous programming project. The following methods comprise the StatPackage.

The function specifications are as follows:

Your StatPackage will accept up to 500 values as input.

Numerical values will be printed with two significant digits to the right of the decimal point.

The program will contain the following functions:

static double calcMean (int scores [], count) calculates the mean value for the values stored in the array scores mean is essentially the same as the average.

static double calcMedian (int scores [], count) calculates the median value for the values stored in the array scores median is the is middle value of the stored values.

static double calcVariance (int scores [], count) calculates the variance value for the values stored in the array scores Variance is determined by the formula:

static double calcStdDev (double variance) calculates the standard deviation value for the values stored in the array scores. Standard deviation is the square root of the variance.

Explanation / Answer


/**
* The java program that generates 500 random values
* (for convenience) and print random values to console.
* Then calculates mean,mediaj,variance and standard
* deviation and print to console.
* */
//StatPackage.java
public class StatPackage
{
   public static void main(String[] args)
   {
       final int count=500;
       int[] scores=new int[count];
       //calling generateRandom method
       generateRandom(scores, count);
       System.out.println("Printing random numbers");
       for (int i = 0; i < scores.length; i++)
       {
           if(i%25==0)
               System.out.println();
          
           System.out.printf("%5d",scores[i]);
       }
      
       //printing mean, median, variance and standard deviation
       System.out.printf(" Mean : %5.2f ",calcMean(scores, count));
       System.out.printf(" Median : %5.2f ",calcMedian(scores, count));
       System.out.printf(" Variance : %5.2f ",calcVariance(scores, count));
       System.out.printf(" Standard deviation : %5.2f ",calcStdDev(calcVariance(scores, count)));
      
   }
  
   //Method that generates 500 random numbers in a range of 0-500
   public static void generateRandom(int arr[],int count)
   {
       for (int i = 0; i < count; i++)
       {
           arr[i]=(int)(Math.random()*500+1);
       }
   }
  
   //Method that calculates the mean
   public static double calcMean (int scores [], int count)
   {
       double total=0;
       for (int i = 0; i < count; i++)
       {
           total+=scores[i];
       }
      
       return total/count;
   }
   //Method that calculates the median
   public static double calcMedian (int scores [], int count)
   {
       double median;
      
       int middleIndex=count/2;
      
       median=scores[middleIndex];
      
       return median;
   }
   //Method that calculates the variance
   public static double calcVariance (int scores [], int count)
   {
       double mean = calcMean(scores,count);
            double temp = 0;
          
            for(double a :scores)
                temp += (a-mean)*(a-mean);
          
            return temp/count;
   }
   //Method that calculates the standard deviation
   public static double calcStdDev (double variance)
   {
       return Math.sqrt(variance);
   }
}


Sample Output:


206 120 453 149 127 491 179 423 413 271 127 359   25 478 289   57   42 336 107 474 100   54 443 479 317
   88 454 219   12   42 342 232   24 482 249 493 115 426 385 483 477 188 255 369 124    5 211   54 444   67
412 175   24 135 100   54 390 375   23 207 132 386 198 236 496 136 139 295 347 137   95 348   58 223 269
   46 250 184 482 387 475 316 174 222 329 131 171 246 194   53 107 334 243 396 438 423   52 274   16 147
157 344 237   44 136 434 332 448 302 133 496   96 376 331   85    2   56   37 284 393 203 473 238 303 434
   78 307 408 264 486 242 314   40 481 293 247 271 133 414   19 124   42 450 153 216   97 432 258   43 156
317   56 294 341 281 409   12 368 445 324    7 468 181 137 203 420 477 462   36 121 116   26 335 426 307
166 117 104 204   61   34 392 144 251 252   20 310   31 393 455 408   86 235 356 375   62 238 320   38 306
   81   55 114 117 278    6 381 204   94 247 313 398 415 153 500 305 391 455 121 256 121 220 321 276 390
182 323 295 415   98 193 433 324 431 233    4 106 214   47 244   25 341 451 384   75 390 473 336 308 227
365 125    6 301 147 161 436 458 401   72 109   31 183   78 260 207 139 276 479 319   84 248 248 271   63
107 385 258 124 359 257 227 305    6 390 288   91 324   14 380 400   73 344 474 449 221 402   34 162 327
395 184 127 363 276 257 452   91 316 403 229   19 150 456 200   87   43   39 119 429 220 167 192 440 470
214 442 383 340 121 242 421 146 148 261 242 144 252    5 386 168 369 143 443 181 456 313    2 171 119
111 109   20   12   18 436 453 437   49   44 436 227 498 372 392   22 231 498 378 461   47 287 433 134 300
225   78 356   43   74   64 373 133 475 274 169 402 219 305 331 150 188 130 273 427 357 367 228 273 277
   87 486 312 168 276 277 324   30 479   51 187 189 359 112 336 257 396 157 194 247 125 306 301 469 381
   79 219 344 209   49   82 458 186   99   52 452 152 253 275 325 431    6 320 292 433 433 480   64 136   95
228 307 278 346   34    5 230 231 211 159 412    5 397 477 238 131 262 200   32 314   16 235   15 173 304
    5 416 160   84 272 488 158 120 163 185 476 289 299 488   68 450 162 403 365 210 277 422 498   29 328
   Mean : 244.91
   Median : 365.00
   Variance : 21084.00
   Standard deviation : 145.20