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

Introduction to user defined functions, parameter and arrays in JAVA programming

ID: 3863858 • Letter: I

Question

Introduction to user defined functions, parameter and arrays in JAVA programming. Can someone help me with my lab, please include comments throughout the code? Thank you!

---------------------------------------------------------------------------------------------------

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:

1. Your StatPackage will accept up to 500 values as input.

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

The program will contain the following functions:

1. 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.

2. 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.

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

4. 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

// StatPackage.java

import java.util.Scanner;
import java.io.*;
import java.lang.*;
import java.lang.Math;

public class StatPackage
{
//calculating mean
static double calcMean(int[] scores, int count)
{
double total = 0;
for(int i=0;i<count;i++){
total = total + scores[i];
}
return total/count;
}
//calculating median
static double calcMedian(int[] scores, int count)
{
double median = 0;
if(count%2 == 0){
median = (scores[count/2 -1] + scores[count/2])/2;
}
else{
median = scores[count/2];
}
return median;
}

//calculating variance
static double calcVariance (int[] scores, int count)
{
double average = calcMean(scores,count);
double total = 0;
for(int i=0;i<count;i++){
total = total + (scores[i]-average) * (scores[i]-average);
}
return total/count;
}

//calculating standard deviation
static double calcStdDev (int[] scores, int count)
{
double variance = calcVariance(scores,count);
return Math.sqrt(variance);
}

public static void main(String[] args)
{
Scanner ip = new Scanner(System.in); // to read user input
int[] scores = new int[500];

System.out.println("Enter 500 scores: ");
for(int i = 0; i < 500; i++)
{
scores[i] = ip.nextInt(); // read in the score
}

System.out.println("Mean: " + calcMean(scores,500));
System.out.println("Median: " + calcMedian(scores,500));
System.out.println("Variance: " + calcVariance(scores,500));
System.out.println("Standard Deviation: " + calcStdDev(scores,500));
}
  
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote