Question

In: Computer Science

Suppose you have a set of data as shown below: {3, 25, 33, 21, 55, 43,...

Suppose you have a set of data as shown below:

{3, 25, 33, 21, 55, 43, 78, 31, 33, 75, 43, 11, 36, 4, 10, 99, A, B, C}

Write a Java class called "DataAnalysis" that has the following methods:

Data_media: this method computes and returns the median of the numerical data;
Data_mode: this method computes and returns the mode of the numerical data;
Data_SortedArray: this method rearranges and returns the data in the increasing order (i.e., smallest to largest).

Solutions

Expert Solution


public class Main
{
   public static void main(String[] args) {
       int[] array={3, 25, 33, 21, 55, 43, 78, 31, 33, 75, 43, 11, 36, 4, 10, 99};
       System.out.println("median is : "+findMedian(array,array.length));
       System.out.println("mode is : "+mode(array,array.length));
       System.out.println("array after sort is : ");
       for(int i=0; i < array.length; i++){
System.out.print(array[i] + " ");
   }
   }
  
static double findMedian(int[] a, int n)
{
// First we sort the array
bubbleSort(a);

// check for even case
if (n % 2 != 0)
return (double)a[n / 2];

return (double)(a[(n - 1) / 2] + a[n / 2]) / 2.0;
}


static int mode(int[] a,int n) {
int maxValue = 0, maxCount = 0, i, j;

for (i = 0; i < n; ++i) {
int count = 0;
for (j = 0; j < n; ++j) {
if (a[j] == a[i])
++count;
}

if (count > maxCount) {
maxCount = count;
maxValue = a[i];
}
}
return maxValue;
}

static void bubbleSort(int[] arr) {
int n = arr.length;
int temp = 0;
for(int i=0; i < n; i++){
for(int j=1; j < (n-i); j++){
if(arr[j-1] > arr[j]){
//swap elements
temp = arr[j-1];
arr[j-1] = arr[j];
arr[j] = temp;
}
  
}
}
}
}



Related Solutions

Suppose you have a set of data as shown below: {3, 25, 33, 21, 55, 43,...
Suppose you have a set of data as shown below: {3, 25, 33, 21, 55, 43, 78, 31, 33, 75, 43, 11, 36, 4, 10, 99, A, B, C} Write a Java class called "DataAnalysis" that has the following methods: Data_NaN: this method filters nonnumerical data, for example, A, B, and C will be filtered out by this method; Data_min: this method computes and returns the minimum of the numerical data;
Suppose you have a set of data as shown below: {3, 25, 33, 21, 55, 43,...
Suppose you have a set of data as shown below: {3, 25, 33, 21, 55, 43, 78, 31, 33, 75, 43, 11, 36, 4, 10, 99, A, B, C} Write a Java class called "DataAnalysis" that has the following methods: Data_max: this method computes and returns the maximum of the numerical data; Data_average: this method computes and returns the average of the numerical data
Here is a set of sample data. 3 87 7 57 15 90 25 55 68...
Here is a set of sample data. 3 87 7 57 15 90 25 55 68 70 89 20 26 93 9 5 86 23 37 52 96 4 91 Base on the data above, identify the 5 number summary _ , _ ,_ , _ , _
Consider the following data. 21, 21, 37, 33, 38, 21, 37 (a) If you were to...
Consider the following data. 21, 21, 37, 33, 38, 21, 37 (a) If you were to construct a normal probability plot by hand for the above data what are the numerical values (in order) of the first five numbers that would go on the y-axis? Separate your answers with a comma. (use Z table)
For the data set shown below, complete parts (a) through (d) below. X 3 4 5...
For the data set shown below, complete parts (a) through (d) below. X 3 4 5 7 8 Y 3 5 8 12 13 (a) Find the estimates of Bo and B1. Bo=bo= _____ (Round to three decimal places as needed.) B1=b1= ______(Round to four decimal places as needed.) (b) Compute the standard error the point estimate for se= ____ (c) Assuming the residuals are normally distributed, determine Sb1=____ (Round to four decimal places as needed.) (d) Assuming the residuals...
For the data set shown below, complete parts (a) through (d) below. X 3 4 5...
For the data set shown below, complete parts (a) through (d) below. X 3 4 5 7 8 Y 4 7 6 12 15 (a) Find the estimates of Bo and B1. Bo=bo= _____ (Round to three decimal places as needed.) B1=b1= ______(Round to four decimal places as needed.) (b) Compute the standard error the point estimate for se= ____ (c) Assuming the residuals are normally distributed, determine Sb1=____ (Round to four decimal places as needed.) (d) Assuming the residuals...
the data set shown​ below, complete parts​ (a) through​ (d) below. x 3 4 5 7...
the data set shown​ below, complete parts​ (a) through​ (d) below. x 3 4 5 7 8 y 5 7 8 12 13 ​(a)  Find the estimates of beta 0 and beta 1. beta 0almost equalsb 0equals nothing ​(Round to three decimal places as​ needed.) beta 1almost equalsb 1equals nothing ​(Round to three decimal places as​ needed.)
the data set shown​ below, complete parts​ (a) through​ (d) below. x 3 4 5 7...
the data set shown​ below, complete parts​ (a) through​ (d) below. x 3 4 5 7 8 y 5 7 6 12 13 ​(a)  Find the estimates of beta 0 and beta 1. beta 0almost equalsb 0equals nothing ​(Round to three decimal places as​ needed.) beta 1almost equalsb 1equals nothing ​(Round to three decimal places as​ needed.)(a)  Find the estimates of beta 0 and beta 1. beta 0almost equalsb 0equals ??​(Round to three decimal places as​ needed.) beta 1almost equalsb...
Consider the following data: 43 54 55 63 67 68 69 77 85 Suppose that the...
Consider the following data: 43 54 55 63 67 68 69 77 85 Suppose that the last value is actually 115 instead of 85. What effect would this new maximum have on the median of the data? increase the value of the median decrease the value of the median no effect Approximately, what z-score divides the lower 75% of the data from the upper 25%? z = 0.75   z = 0.675   z = - 0.675   z = -0.25   none of...
Consider the following set of ordered pairs. x 33 11 55 44 y 44 33 44...
Consider the following set of ordered pairs. x 33 11 55 44 y 44 33 44 44 ​a) Calculate the slope and​ y-intercept for these data. ​b) Calculate the total sum of squares​ (SST). ​c) Partition the sum of squares into the SSR and SSE.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT