Your instructor will assign one or more of the following problems. Submit all appropriate files for grading, including code files, screen captures, supplemental files (e.g., image files), and text files.
For each of the exercises below, write a driver program that asks the user how many values they would like to analyze, and then populates an appropriate array with values entered by the user. Finally, test the method written for the exercise using the user-input array.
When people talk about an average value, most often they are referring to the arithmetic mean (sum of the values, divided by the number of values). There are, however, other “measures of central tendency.” For example, the geometric mean of a sequence of n values is the nth root of the product of all the values. A simple algorithm to compute the geometric mean of a sequence of values is
Algorithm Let n
be the number of values in the sequence.
- Given:
values
is a sequence with at least one value.- Initialize
gMean
to 1.- For each
value _{i}
:
SetgMean
to be the product ofgMean
andvalue _{i}
.- Return the
n
th root ofgMean
.
Write a method that computes the geometric mean of an array of values. Test this method by
using it to compute and display the geometric mean of data input by the user. Be sure to include
appropriate documentation. Hint: To compute the n
th root of a
value x you can use Math.pow(x, 1.0/n)
While a mean tells you something about the central tendency of your data, the standard deviation instead measures the amount of variability or diversity in your data.
To compute a complete population's standard deviation, you can use the following algorithm:
Algorithm Let n
be the number of values in the sequence.
- Given:
values
is a sequence with at least one value.- Initialize
mean
to be the average ofvalues
.- Initialize
discriminant
to be 0.- For each
value_{i}
:
Setdiscriminant
to be the sum ofdiscriminant
and(value_{i} - mean)^{2}
.- Set
discriminant
to bediscriminant / n
- Return the square root of
discriminant
.
Write a method that computes the standard deviation of an array of values. Test this method by using it to compute and display the standard deviation of data input by the user. Be sure to include appropriate documentation.
A histogram counts the number of times each of the numeric values occur. Usually we see histograms as a graph:
74: *** 75: ***** 76: ****** 77: 78: **
This graph of the histogram indicates that the value 74 was seen three times, the value 75 was seen five times, 76 seen six times, 77 seen zero times, and 78 seen two times. All other values were never seen.
Write the following two methods:
computeHistogramGraph()
receives an array of numeric scores and counts the
number of times that particular numeric scores occur in the given array. The method returns an
appropriate string, formatted as shown above. Note that you should include only the values
between the minimum and maximum scores (inclusive).computeHistogramTable()
displays the raw histogram data; for example:
74:3 75:5 76:6 78:2
Here, you skip all values with a 0 count.
Test both of these methods using an array whose values were received from the user. Be sure to include appropriate documentation.
Extend the lab exercise by designing and implementing an algorithm for a method that counts the number of each unique words in a text. The method should receive an array of words and print out each unique word along with a number of occurrences of that word in the array.
Refer to the previous question for a discussion of histograms. Your instructor will indicate whether you should print numbers for the counts or histogram bars.
Write a method that receives an array of city names, low and high temperatures (see for example, weatherStats.java) and returns an array of four Strings with the following statistics:
In each case, concatenate the value together with the name of the city that produced it (e.g., "Grand Rapids 72"). If there are ties, you may arbitrarily decide which city name to report). Print the resulting array, one statistic per line.
Be sure to test your method using the constant in weatherStats.java (copy and paste it to the bottom of your class as we did in lab), and print the resultant array, one statistic per line.
Submit all appropriate files for grading, including code files, screen captures, supplemental files (e.g., image files), and text files. We will grade this exercise according to the following criteria:
If you work in teams for this homework assignment, be sure to submit all team members’ names in the code documentation.