Java Code Help! Code this: Calculate statistics. Write a class called Statistics that can calculate a number of properties about an array of doubles. There should be separate static methods to calculate the min, the max, the mean, the median, the standard deviation (make sure to make use of your mean method to implement this), and the mode. For the mode, you can assume that the data set is not multimodal. This class should not have a main method. Write a separate tester class called StatisticsTester which only has a main method. When run, it will ask the user for how many numbers they wish to enter and then allow the user to enter that many numbers. Store those numbers in an array and run each of the methods from the Statistics class on this data set. Print out the results.
Statistics.java:
class statistics {
static double myarray[]=new double[50];
static double sortedarr[]=new double[50];
public static double min(){
int i;
double min=0;
for (i=0;i<myarray.length;i++){
if(myarray[i]<=myarray[i+1]) //compare every 2 consecutive
elements of array and store the min
min=myarray[i];
}
return min;
}
public static double max(){
int i;
double max=0;
for (i=0;i<myarray.length;i++){
if(myarray[i]>=myarray[i+1]) //compare every 2 consecutive
elements of array and store the max
max=myarray[i];
}
return max;
}
public static double mean(){
int i;
double mean=0;
for (i=0;i<myarray.length;i++){
mean=mean+myarray[i];
}
mean=mean/myarray.length;
return mean;
}
public static double stdDeviation(){ //apply the formula
(sum(i*i)/n)-(sum(i)/n)^2
int i;
double std=0,std1=0,std2=0;
for (i=0;i<myarray.length;i++){
std1=myarray[i]*myarray[i];
}
std1=std1/myarray.length;
std2=mean()*mean();
std=std1-std2;
return std;
}
public static double median(){
int n=myarray.length,c,d,med1;
double med=0,swap;
sortedarr=myarray;
//first apply bubble sort to sort the array
for (c = 0 ; c < ( n - 1 ); c++)
{
for (d = 0 ; d < n - c - 1; d++)
{
if (sortedarr[d] > sortedarr[d+1]) /* For decreasing order use
< */
{
swap = sortedarr[d];
sortedarr[d] = sortedarr[d+1];
sortedarr[d+1] = swap;
}
}
}
//take median of sorted array
med1=n/2;
med=sortedarr[med1];
return med;
}
public static double mode(){
int i,n=myarray.length,k,j;
double mode=0,max=0;
for (i = 0; i < n - 1; i++)
{
mode = 0;
for (j = i + 1; j < n; j++)
{
if (myarray[i] == myarray[j]) {
mode++;
}
}
if ((mode > max) && (mode != 0)) {
k = 0;
max = mode;
}
}
return max;
}
}
StatisticsTester.java:
import java.util.Scanner;
public class StatisticsTester{
public static void main(){
statistics tester=new statistics();
Scanner in=new Scanner(System.in);
int number,i;
double min,max,mean,med,std,mode;
System.out.println("How many numbers do you want to
enter?\n");
number=in.nextInt();
for(i=0;i<number;i++){
System.out.println("Enter the number\n");
tester.myarray[i]=in.nextDouble();
min=tester.min();
max=tester.max();
mean=tester.mean();
med=tester.median();
std=tester.stdDeviation();
mode=tester.mode();
System.out.println("In the class statistics, for the entered
numbers\n min is "+min+"\nmax is "+max+"Median is "+med+"Standard
deviation is "+std+"Median is "+med+"Mode is "+mode);
}
}
}
Java Code Help! Code this: Calculate statistics. Write a class called Statistics that can calculate a...
Write a class called Person that has two private data members - the person's name and age. It should have an init method that takes two values and uses them to initialize the data members. It should have a get_age method. Write a separate function (not part of the Person class) called basic_stats that takes as a parameter a list of Person objects and returns a tuple containing the mean, median, and mode of all the ages. To do this,...
java programming!!!
Write the code fragment that will do the following: • Ask the user how many numbers they want to enter • Declare and instantiate an array of doubles with as many elements as the number entered by the user • Write one 'for' loop to fill the array with data from the user • Write a second 'for' loop to calculate the sum of all of the numbers in the array • Print the calculated sum Note: Write...
Write code in static void main method class, which creates a boolean array called flags, size 10, and using a for loop sets each element to alternating values (true at index zero, false at index one Write code in a static void main method class, which creates a float array called sales, size 5, uses an initializer list to instantiate its elements with positive values having two decimal places (example 7.25), and using a for loop reads those values of...
In c++ Write a program that contains a class called Player. This class should contain two member variables: name, score. Here are the specifications: You should write get/set methods for all member variables. You should write a default constructor initializes the member variables to appropriate default values. Create an instance of Player in main. You should set the values on the instance and then print them out on the console. In Main Declare a variable that can hold a dynamcially...
In Java: Main function must be in a separate class called "IncomeDemo" Write an "Income" class that stores the total monthly income for each of the 12 months into an array of doubles. The class should have methods that return the following: total income for the year average monthly income the month with the highest income the month with the lowest income Write a program that demonstrates this class. You'll need to pass a 12-element double array to the class...
In C++ Write a program that contains a class called VideoGame. The class should contain the member variables: Name price rating Specifications: Dynamically allocate all member variables. Write get/set methods for all member variables. Write a constructor that takes three parameters and initializes the member variables. Write a destructor. Add code to the destructor. In addition to any other code you may put in the destructor you should also add a cout statement that will print the message “Destructor Called”....
pls help java ASAP!!!!!!!
Topic String Tokenizer Static Methods Static Variables Primitive Arrays Description Enhance the last assignment by providing the following additional features: (The additional features are listed in bold below) Class Statistics In the class Statistics, create the following static methods (in addition to the instance methods already provided). • A public static method for computing sorted data. • A public static method for computing min value. • A public static method for computing max value. • A...
Create a class called Play that has an InputReader as an instance variable. Be sure to initialize it in the constructor. The class has two methods. Write a method with this signature: Write a method with this signature: public void stringPlay() The method prompts the user for a string, reads it in, and then displays the string as many times as the length of that string. The output string should be formatted with the first letter uppercase and the rest...
Registration Language Java Step 1: Design a class called Student. The Student class should contain the following data: firstName lastName studentID totalCredits gpa Your class should implement the “sets” and “gets” for the class. Include methods: equals, compareTo, toString. Change the toString method (from class) to put each member variable on a new line. Step 2: Write a driver program to test that Student works correctly. Test is with 3 students as given in class. Step 3: Write a “registration”...
create a new Java application called "Scorer" (without the quotation marks) that declares a two-dimensional array of doubles (call it scores) with three rows and three columns and that uses methods and loops as follows. Use a method containing a nested while loop to get the nine (3 x 3) doubles from the user at the command line. Use a method containing a nested for loop to compute the average of the doubles in each row. Use a method to...