Ask your own question, for FREE!
Computer Science 18 Online
OpenStudy (anonymous):

Write two Java programs. First program is MyStatistics.java which contains the following static methods. You may not use existing methods provided by Java but you may invoke methods in this MyStatistics class. For example, you may use findMax and findMin to derive your range value for the findRange method.

OpenStudy (anonymous):

I assume the rest will follow...

OpenStudy (anonymous):

1. public static int findMax(int[] numbers) This method finds the maximum value from the input array named numbers. 2. public static int findMin(int[] numbers) This method finds the minimum value from the input array named numbers. 3. public static int findRange(int[] numbers) To compute the range of a set of values, simply subtract the lowest value from the highest value in the array named numbers. 4. public static int findSum(int[] numbers) This method finds the sum of all values stored in the array named numbers. 5. public static double findMean(int[] numbers) The mean of a set of values stored in the array named numbers can be found by adding the values in the array and dividing the total by the number of values. 6. public static double findMedian(int[] numbers) To find the median, first sort the values in order (You may use the sort method from the Arrays class provided by Java.) Check out the API page for its usage, and then follow one of these two procedures a. If the number of values is odd, the median is the number located in the exact middle of the array. b. If the number of values is even, the median is found by computing the mean of the two middle numbers in the sorted array. . 7. public static double findSTD(int[] numbers) The standard deviation S is computed using the formula listed above. Procedure for finding the standard deviation with this formula: a. Compute the mean first. b. Subtract the mean from each individual value to get a list of deviations of the form (x - ). You access each value in the array by subscripted array index. Remember array indices begin at 0. c. Square each of the differences obtained from step b. d. Add all of the squares obtained from step c. e. Divide the total from step d by the number (n -1), which is 1 less than the total number of values present in the array. f. Find the square root of the result of step e. Next, write another Java program named MyStatisticsDemo.java which contains the main method and performs the following tasks: a. Display your name to the screen and some info you get from the user’s computer and the date the program is executed. Use the same method you used for your previous assignment. b. Ask user for the number of nonnegative whole numbers to be entered, create an array of that length, and then ask the user to enter the numbers one at a time. c. Your program will store the numbers in an array. d. If the input number is negative. · You ignore the number (do not accept it nor use it in your calculations) · You give user a warning that an illegal negative number has entered. · Go back to your loop and ask for another input. e. After the user has entered all the numbers, your program then will invoke all the methods found in the MyStatistics class and calculate the statistics and output them to the screen all in one line with proper heading: ( printf method would work for this.) · The number of input numbers. · The largest number · The smallest number. · The sum, · The range, · The average of all the input numbers with three decimal places. · The standard deviation of the input numbers with three decimal places. · The median with 1 decimal place. · If there is no valid input, give the user this info. Decide an output statement if user does not enter any number, for example, user enters -1 for the first number. An example of output statistics from this program: Count Sum Max Min Range Median Mean STD 20 190 19 0 19 9.0 9.500 5.788

OpenStudy (anonymous):

So which part are you having trouble with?

OpenStudy (anonymous):

6 and 7

OpenStudy (anonymous):

more specific, please. do you understand what they're asking but you don't know how to implemenmt it? show us your work, starting with what you have for exercise 6 (do 7 later or in a separate question)

OpenStudy (anonymous):

i dont understand no. 6

OpenStudy (anonymous):

what part of 6; what have you got so far?

OpenStudy (anonymous):

so far i have public class MyStatistics { public static int findMax(int[] numbers){ int max = numbers[0]; for(int i = 0; i <= numbers.length; i++){ if(numbers[i] > max){ max = numbers[i]; } } return max; } public static int findMin(int[] numbers){ int min = numbers[0]; for(int i = 0; i <= numbers.length; i++){ if(numbers[i] < min){ min = numbers[i]; } } return min; } public static int findRange(int[] numbers){ int Range = findMax(numbers) - findMin(numbers); return Range; } public static int findSum(int[] numbers){ int sum = 0; for(int i = 0; i < numbers.length; i++){ sum = sum + numbers[i]; } return sum; } public static double findMean(int[] numbers){ double Mean = findSum(numbers) / numbers.length; return Mean; } }

OpenStudy (anonymous):

[sry gotta go, it's late here, someone else will surely chime in]

OpenStudy (anonymous):

I meant what have you got for nr.6

OpenStudy (anonymous):

nothing

OpenStudy (espex):

On first glance it appears that you have what you need for 6, what is it I am missing?

OpenStudy (anonymous):

i need help in sorting the values in order

OpenStudy (espex):

You have already sorted them when you did your max/min method.

OpenStudy (espex):

According to your instructions, (You may use the sort method from the Arrays class provided by Java.) which is simply passing the array to sort(). http://docs.oracle.com/javase/1.4.2/docs/api/java/util/Arrays.html

OpenStudy (anonymous):

java util.Array

OpenStudy (espex):

I should correct my previous statement, when I said you already sorted them in your max/min function. You have the logic necessary to sort, you just need a temp variable to store the swapped value in. However that is not necessary now that you can use the sort() method.

OpenStudy (espex):

You could do: sort(numbers, a); and have it sort the array in ascending order.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!