I need help with a program please, having problems just getting started on this
ID: 3683289 • Letter: I
Question
I need help with a program please, having problems just getting started on this without getting an error for trying to do the array and how to call back what was put into it. Here is what we are supposed to do and bellow that is my current program. Thanks
Write an error-free Java program to do the following things.
Prompt the user to input a set of numbers. The numbers represent temperatures so they will be between -10 and 130. The user should be able to input up to 40 numbers but if the user enters -101 then the data input ceases. All of the data that the user enters should be stored in a single array. You do not need to check the input data to see if it is in the proper range – assume the user will input correct data. Also, the user will only input integers but the data does not need to be stored as integers.
The program should calculate the average, the variance and the kurtosis of the numbers that were entered. Note that the numbers could be positive or negative. The equation for the average is given in the book. The formula for the variance and the kurtosis (fourth centralized moment) is given by
Variance = sum (Xi - Xbar)^2 /(n-1)
kurtosis = (sum(Xi - Xbar)^4) / ((n)(var)^2) - 3
where xi are the individual numbers, n is the number of data points, var is the variance, and is the average of the sample. Kurtosis gives an indication of how “peaked” the data samples are relative to a normal (Gaussian) distribution.
The kurtosis must be calculated via a call to a method.
At the end, the program should repeat all of the numbers on one line and then print the average, variance, and kurtosis of the data sample.
\so far this is my program
import java.util.Scanner;
public class arrayVariance
{
public static void main( String[] args )
{
double[] array = new double[40];
Scanner in = new Scanner(System.in);
System.out.println("Enter data value, enter -101 to quit. ");
while(array!=-101&&array.length<40)
{array[] = in.nextInt()};
for( int i = 0; i < array.length; i++ )
{
double sum = math.sum(array[i]);
double avg = sum/array.length;
double xx =(array[i]-avg);
double var =(math.Sum(xx*xx))/(array.length-1)
double kur =((math.Sum(xx*xx*xx*xx))/(array.length*var*var))-3
System.out.println("the data values are:" +array[i]);
System.out.println("Average= "+avg+", variance= "+var+", kurtosis= "+kur);}
}
}
Explanation / Answer
import java.util.Scanner;
import java.lang.Math;
public class arrayVariance
{
public static void main( String[] args )
{
double[] array = new double[40];
double sumv=0,sumk=0,sum=0,avg, xx, var, kur;
int i=0;
Scanner in = new Scanner(System.in);
System.out.println("Enter data value, enter -101 to quit. ");
while(true)
{
array[i] = in.nextInt();
if(array[i]==-101 || array.length<40)
break;
}
for( i = 0; i < array.length; i++ )
{
sum = sum+array[i];
}
avg = sum/array.length;
for( i = 0; i < array.length; i++ )
{
xx =(array[i]-avg);
sumv=sumv+xx*xx;
sumk=sumk+xx*xx*xx;
System.out.println("the data values are:" +array[i]);
}
var =sumv/(array.length-1);
kur =sumk/(array.length*var*var)-3;
System.out.println("Average= "+avg+", variance= "+var+", kurtosis= "+kur);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.