C Sc 227 Project 3, Summer 07: Arrays in Classes



Project: DescriptiveStatistics

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. The following code is also available as the download DescriptiveStatistics.java

// A DescriptiveStatistics object allows users to add numeric data and get

// descriptive statistics such as max, min, average, range, mode, 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).

public class DescriptiveStatistics {

// Construct an empty collection of doubles that can store any number of doubles

public DescriptiveStatistics() {

// TODO: Complete this constructor

}

// The number of doubles that have been added to this collection, 0 at first

public int size() {

// TODO: Complete this method

return -1;

}

// Add aNumber to the collection while maintaining a natural ordering.

// The array will grow if necessary.

public void addInOrder(double aNumber) {

// TODO: Complete this method

}

// Retrieve the element at the given index.

// Precondition: index >= 0 && index < size()

public double get(int index) {

// TODO: Complete this method

return 0.0;

}

// Return the average, rounded to 1 decimal, of all numbers added to this object

// Return 0.0 if no numbers have been added. Hint: Use double roundToOneDecimal(double)

public double average() {

// TODO: Complete this method

return roundToOneDecimal(0.9999999); // should be 1.0

}

// Return the rounded value to first decimal place of given double value.

public double roundToOneDecimal(double number) {

number = Math.round(10.0 * number) / 10.0;

return number;

}

// 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() {

// TODO: Complete this method

return 0.0;

}

// 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() {

// TODO: Complete this method

return 0.0;

}

// 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() {

// TODO: Complete this method

return 0.0;

}

// 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.

public double median() {

// TODO: Complete this method

return 0.0;

}

// Return the standard deviation, rounded to 1 decimal place of all numbers

// added to this object. Return 0.0 if n ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download