Revise the Statistician with median (Programming Project 15 on page 172) so that it stores the input
Question:
Revise the Statistician with median (Programming Project 15 on page 172) so that it stores the input numbers on a doubly linked list using the doubly linked node class from the previous project. Rather than a head reference, you should have an instance variable that keeps track of the node that contains the current median and two instance variables that tell how many numbers are before and after this median. Keep the numbers in order from smallest to largest. Whenever a new item is inserted, you should check to see whether it goes before or after the median. After the new item is inserted, you might have to move the median pointer forward or backward.
Data from Project 15
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.
Step by Step Answer: