C Sc 227 Project: Descriptive Statistics

Develop class DescriptiveStatistics and unit test DescriptiveStatisticsTest with the following methods using the exact same method headings such that each one fulfills the responsibilities described in comments. A DescriptiveStatisticsobject allows users to add numeric data and determine descriptive statistics such as max, min, average, range, and sample standard deviation. You must use an array instance variable. Each new value must be added at the end of the array during an add(double) message.In other words, the first value must be added at index 0, the second value at index 1, and a 3rd value at index 2, or in general, all doubles added to a DescriptiveStatistics object must be added to the array at index size()-1.

/**

*Constructanemptycollectionofdoublesthatcanstore

*upto10 floatingpointnumbers.

*/

public DescriptiveStatistics()

/**

*Thesizeofthiscollection.

*@returnThenumberofelementsaddedtothisobject.

*/

publicint size()

/**

*AddaNumber at the end of the array, specifically at array index size()-1.

* Grow thearray if necessary.

*

*@paramaNumberisthedatum toaddtothisobject.

*/

publicvoid add(double aNumber)

/**

*Get the element at the given index.

*

* Precondition: index >= 0 & index < size(). Do not test for this in get

*

* @param The index of the element to be returned assuming index is in range

*/

public double get(int index)

/**

*Returntheaverageofallnumbersaddedtothis

*object.Return0.0ifnonumbershavebeenadded.

*

*@returnTheaverageofallnumbers.

*/

publicdouble average()

/**

*Returnthemaximumvalueofallnumbersaddedto
*thisobject.Return0.0ifnonumbershavebeenadded.

*/

publicdouble max()

/**

*Returntheminimumvalueofallnumbersaddedtothisobject.

* Return0.0ifnonumbershavebeenadded.

*/

publicdouble min()

/**

*Returntherange(max()-min())ofallnumbersaddedtothisobject.

*Return0.0ifnonumbershavebeenadded.

*/

publicdouble range()

/**

*Returnthemedianofallnumbers.

* Themedianisthenumberthatdividesthedistributioninhalf.Forexample,

*the medianof1.0,2.0,3.0=2.0.Ifthereisanevennumberofelements,

*usetheaverageofthetwointhemiddle.Forexample,themedianof1.1,

*2.2,3.3,4.4is(2.2+3.3)/2.0=2.75.

*

*Return0.0ifnonumbershavebeenaddedtothisobject.

*

*@returnThemedianofthesenumbers(usesaveragingwhensize()iseven)

*/

publicdouble median()

/**

*Returnthestandarddeviationofallnumbers added

*tothisobject.Return0.0ifn<= 1. Example:

*

* Thestandarddeviationofthenumbers1.03.05.0is

* Math.sqrt(((1.0-3.0)^2+(3.0-3.0)^2+(5.0-3.0)^2)/2.0)=2.0

*

* Thestandarddeviationofthenumbers1.53.24.7is1.601041.

*

*@returnThesamplestandarddeviation

*/

publicdouble standardDeviation()

Use the following formula for sample standard deviation:

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:

importstatic org.junit.Assert.*;

import org.junit.Test;

publicclass DescriptiveStatisticsTest {

@Test

publicvoid testFailedWhileTestingAddAndGet() {

DescriptiveStatistics list1 = new DescriptiveStatistics();

assertEquals(0, list1.size());

list1.add(4.04);

assertEquals(4.04, list1.get(0), 1e-12);

list1.add(3.3);

list1.add(9.99);

list1.add(2.2);

assertEquals(4.04, list1.get(0), 1e-12);

assertEquals(3.3, list1.get(1), 1e-12);

assertEquals(9.99, list1.get(2), 1e-12);

assertEquals(2.2, list1.get(3), 1e-12);

assertEquals(4, list1.size());

}

// Add other test methods and assertions to thoroughly test every method.

}

Grading Criteria (subject to change)

Note: Here are several ways that can result in a score of 0% even though all of your tests passed in your workspace:

  1. WebCat reports a compile time error such as Unknown symbol
  2. One of Rick's test cases threw your loop into an infinite loop (timeout error)
  3. One of your assertions failed on WebCat (even though it passed for you locally)
  4. All of your tests must pass on WebCat, not just locally
  5. You did not submit a unit test, so you receive 0% code coverage (0 * 100 is 0)

____+80 Web-Cat correctness and code coverage: To get 80 points, you will need 100% code coverage and 100% problem coverage (Rick's tests pass and you exercised all methods). These 100 points are derived from Web-Cat. You may submit as many times as you wish until you have 100% on both. Notice that a multiplication feature is employed that means 90% code coverage and 90% problem coverage results in 0.9 * 0.9 * 80 for 64/80 points. This is only 81% rather than 90% for this portion of the grade.

___/ +20 Style and Design

+2 Each class has your name and a description of the class in comments.

+2 Each class has your section leader name in a comment.

+2 You wrote a comment to describe each method (or use what is given in the interface).

+2 You used intention-revealing names (meaningful identifiers)

+2 Used consistent spacing/indentation--format all code with the Eclipse shortcut Source > Format

+2 All methods are separated by one blank line

+2 The code is easy to understand by other programmers

+2 Has no unnecessary code (check code coverage for ifs that are always true or always false.,,)

+2 Did not use an instance variable where a local variable is more appropriate

+2 Used public and private where appropriate

Please note these other possibilities for loosing points (0 is the minimum score)

____-80 If you did not use a 1D array of doubles as an instance variable in DescriptiveStatistics.

-80 for any other scenario such as using an existing Java collection class.