Assign11- Word FERENCES MAILINGS REVIEW VIEW Assigned: Friday, 13 October 2017 D
ID: 3594467 • Letter: A
Question
Assign11- Word FERENCES MAILINGS REVIEW VIEW Assigned: Friday, 13 October 2017 Due: Wednesday, 18 October 2017 Points: 20 Write an error-free Java program to do the following things. .Prompt the user to input a set of numbers. The user should be able to input up to 20 numbers but if the user enters- 1 then the data input ceases. All of the data that the user enters should be stored in a single array. The numbers may be integers or non-integers and can be positive or negative The program should calculate the average, the standard deviation and the skewness of the numbers that were entered. The formulas for the variance and the skewmess (the thard centralized moment) are given by · (x- Standard deviation (n-I) (x-5), (n-1)s Skewness= wherc x are the individual numbers, a is the number of data points, s is the standard deviation, and is the average of the sample. The skewness and the standard deviation must be calculated via calls to a is, there must be a method that calculates the standard deviation and a separate method that calculates the skewness · At the end, the program should repeat all of the numbers on one line and then print the average, standard deviation, and skewness of the data sample. Example: Enter data value (-1 to quit): Enter next data value (-1 to quit) : | Enter next data value (-1 to quit): Enter next data value (-1 to quit):Explanation / Answer
package org.students;
import java.util.Scanner;
public class MeanStandDevSkew {
public static void main(String[] args) {
//Creating an Array of double whose size is 20
double nos[] = new double[20];
double num, average = 0.0, sum = 0.0;
//Declaring variables
int count = 0;
/*
* Creating an Scanner class object which is used to get the inputs
* entered by the user
*/
Scanner sc = new Scanner(System.in);
//Getting the input entered by the user
System.out.print("Enter data value (-1 to quit ) :");
num = sc.nextDouble();
/* This while loop continues to execute
* until the user enters a negative number or count is equal to 20
*/
while (num != -1 && count != 20) {
nos[count] = num;
sum += nos[count];
count++;
System.out.print("Enter data value (-1 to quit ) :");
num = sc.nextDouble();
}
//calculating average
average = sum / count;
//Displaying the output
System.out.println("The average is " + average);
//calling the method
double stdDev = calStandardDev(average, count, nos);
//Displaying the output
System.out.println("The standard deviation is " + stdDev);
//calling the method
double skewness = calSkewness(average, count, nos, stdDev);
//Displaying the output
System.out.println("The skewness is " + skewness);
}
//This method will calculate the Skewness
private static double calSkewness(double average, int count, double[] nos,
double stdDev) {
double skewness;
double sum2 = 0.0;
//Calculating the part of standard deviation
for (int i = 0; i < count; i++) {
sum2 += Math.pow((nos[i] - average), 3);
}
skewness = (sum2) / ((count - 1) * Math.pow(stdDev, 3));
return skewness;
}
//This method will calculate the standard deviation
private static double calStandardDev(double average, int count, double[] nos) {
double deviation;
double sum2 = 0.0;
//Calculating the part of standard deviation
for (int i = 0; i < count; i++) {
sum2 += Math.pow((nos[i] - average), 2);
}
//Calculating standard deviation
deviation = Math.sqrt((sum2) / (count - 1));
return deviation;
}
}
__________________
Output:
Enter data value (-1 to quit ) :67
Enter data value (-1 to quit ) :98
Enter data value (-1 to quit ) :89
Enter data value (-1 to quit ) :45
Enter data value (-1 to quit ) :-1
The average is 74.75
The standard deviation is 23.725864929790582
The skewness is -0.28288515763584543
_____________Could you rate me well.Plz .Thank You