Implement the previous project with the following modification: All of the input numbers to the Statistician are

Question:

Implement the previous project with the following modification: All of the input numbers to the Statistician are required to be integers in the range from 0 to 100. This modification means that it’s easier to keep track of all the input numbers using a single array (called frequency) with indexes from 0 to 100. At all times, the value of frequency[i] will be the number of times the number i has been given to the Statistician.

You will need to give it some thought to figure out how to use the frequency information to compute statistics such as the median and the mean.


Data from Previous Project

Implement the Statistician class from Project 2 on page 95, but include a new method that returns the median value of all the numbers. The median is a number that is greater than or equal to at least half of the numbers and is also less than or equal to at least half of the numbers.

Because of the new median calculation, the Statistician will need to keep track of all the numbers, perhaps using an array. The median calculation will be easiest if you keep these numbers in order from smallest to largest.


Data from Project 2

Specify, design, and implement a class called Statistician. After a statistician is initialized, it can be given a sequence of double numbers. Each number in the sequence is given to the statistician by activating a method called nextNumber. For example, we can declare a statistician called s and then give it the sequence of numbers 1.1, –2.4, 0.8, as shown here:

Statistician s = new Statistician( );

s.nextNumber(1.1);

s.nextNumber(-2.4);

s.nextNumber(0.8);

After a sequence has been given to a statistician, there are various methods to obtain information about the sequence. Include methods that will provide the length of the sequence, the last number of the sequence, the sum of all the numbers in the sequence, the arithmetic mean of the numbers (i.e., the sum of the numbers divided by the length of the sequence), the smallest number in the sequence, and the largest number in the sequence. Notice that the length and sum methods can be called at any time, even if there are no numbers in the sequence. In this case of an “empty” sequence, both length and sum will be zero. The other methods should return Double.NaN if they are called for an empty sequence.

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question
Question Posted: