Please write this Java program as simple as possible and with comments throughou
ID: 3730207 • Letter: P
Question
Please write this Java program as simple as possible and with comments throughout explaining what is happening. Thank you!Program 2 (30 points): Design and implement a Java program for programming exercise 7.11, page 278 (name it Sta in the problem stat any number of elements, not just 10 as shown in the textbook m Follow the instructions in the problem statement. Design the main method of your program to handle all input tis tics), to compute the mean and deviation of a set of numbers stored in an array as specified tement (the methods deviation () and mean ) must be designed to handle arrays with model). Use the sample run to test your code and output and to organize the output using appropriate formatting techniques. allow the user to re-run the program with different sets of inputs. Document your code and
Explanation / Answer
ScreenShot
-----------------------------------------------------------------------------------------------------------
Code:-
//HeaderFiles
import java.util.ArrayList;
import java.util.Scanner;
import static java.lang.Math.sqrt;
import java.text.DecimalFormat;
//Public class
class statistics {
//Main metod
public static void main(String[] args) {
//formatter to format decimal
DecimalFormat df = new DecimalFormat("#.#####");
//Scanner to read input
Scanner keyboard = new Scanner(System.in);
//Arraylist resizeable array
ArrayList<Double> numbers = new ArrayList( );
//To find enter key press
String input = keyboard.nextLine();
//Enter value in array
System.out.print("Entered ArrayValues :" );
//Loop to add value in array
for(String item : input.split(" ")){
numbers.add(Double.parseDouble(item));
}
//array print
System.out.println(numbers);
//mean value print
System.out.println("Mean = "+df.format(mean(numbers)));
//Deviation print
System.out.println("Deviation = "+df.format(deviation(numbers)));
}
//Method to calculate deviation
public static double deviation(ArrayList<Double> x){
//variable declaration
double deviationval=0,meanValue=0,deviationValue;
//loop to get each value and calculate mean
for(int i=0;i<x.size();i++){
meanValue+=(x.get(i)/x.size());
}
//loop to get each value and calculate deviation
for(int i=0;i<x.size();i++){
deviationval+=Math.pow((x.get(i)-meanValue),2)/(x.size()-1);
}
deviationValue=sqrt(deviationval);
//return deviation
return deviationValue;
}
//method to find mean
public static double mean(ArrayList<Double> x){
double meanValue=0;
//loop to find mean
for(int i=0;i<x.size();i++){
meanValue+=(x.get(i)/x.size());
}
//return mean
return meanValue;
}
}