Download Custom Data Structure for Descriptive Statistics: Project Implementation and more Study Guides, Projects, Research Computer Science in PDF only on Docsity! C Sc 227 Project 3: Descriptive Statistics Due Date: Tuesday, 17-Feb @ 10:00 8:00 pm via WebCat Descriptive Statistics Develop class DescriptiveStatistics and a unit test with the following methods using the specific method headings to fulfill the responsibilities described in comments. A DescriptiveStatistics object allows users to add numeric data (up to the computer's capacity) and get descriptive statistics such as max, min, average, range, and sample standard deviation. The numeric data is maintained in a natural ordering with the minimum value at get(0) and the maximum at get(size()-1). /** * Construct an empty collection of doubles that can store up to any number * of floating point numbers as long as the computer has memory. */ public DescriptiveStatistics() /** * The size of this collection. * @return The number of elements added to this object. */ public int size() /** * Add aNumber to the collection while maintaining a natural ordering. * Precondition: The computer has enough memory to either add aNumber. * * The array will grow if necessary. * * @param aNumber is the datum to add to this object without rounding it. */ public void addInOrder(double aNumber) /** * Get the element at the given index. * @param The index of the element to be returned */ public double get(int index) /** * * Return the average, rounded to 1 decimal, of all numbers added to this * object. Return 0.0 if no numbers have been added. * * @return The average of all numbers. */ public double average() /** * Return the maximum value, rounded to 1 decimal, of all numbers added to * this object. Return 0.0 if no numbers have been added. */ public double max() /** * Return the minimum value, rounded to 1 decimal, of all numbers * added to this object. Return 0.0 if no numbers have been added. */ public double min() /** * Return the range (max()-min()) of all numbers added to this object * rounded to 1 decimal place. Return 0.0 if no numbers have been added. */ public double range() /** * Return the median of all numbers rounded to 1 decimal place. The median * is the number that divides the distribution in half. For example, the * median of 1.0, 2.0, 3.0 = 2.0. If there is an even number of elements, * use the average of the two in the middle. For example, the median of 1.1, * 2.2, 3.3, 4.4 is (2.2+3.3) / 2.0 = 2.75 which when rounded = 2.8. * Return 0.0 if no numbers have been added to this object. * * @return The median of these numbers (uses averaging when size() is even) */ public double median() /** * Return the standard deviation, rounded to 1 decimal place of all numbers * added to this object. Return 0.0 if n <= 1. Example: * the standard deviation of the numbers 1.0 3.0 5.0 is * Math.sqrt(((1.0-3.0)^2 + (3.0-3.0)^2 +(5.0-3.0)^2) / 2.0) = 2.0 The * standard deviation of the numbers 1.5 3.2 4.7 is 1.601041 or 1.6 rounded. * For other examples, use MS-Excel and the STDEV function. * * @return The sample standard deviation */ public double standardDeviation() Use the following formula for sample standard deviation (Rick changed n to n-1 after class) Include a Unit Test Make sure you have a unit test with assertions that fully test each method specified above. This class name must end with Test. Here is a start: import static org.junit.Assert.*; import org.junit.Test; public class DescriptiveStatisticsTest { @Test public void testFromProjectSpec() { DescriptiveStatistics list1 = new DescriptiveStatistics(); assertEquals(0, list1.size()); list1.addInOrder(4.04); assertEquals(4.04, list1.get(0), 1e-12); list1.addInOrder(3.3); list1.addInOrder(9.99); list1.addInOrder(2.2); assertEquals(2.2, list1.get(0), 1e-12);