Percentile - the parameter * percent and sorter algorithm...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
package  sequenceSummary; import  java.util .*; /**  * A percentile object provides a utility for finding the nth   percentile over  * an array of objects.  The percentile can be found by sorting the  objects,  * then iterating until the relevant element is found.  * For example, if we have 201 objects and the Percentile represented  is the median  * (percentile = .5), then we would return the 100th object.  * Note that if there are an even number of objects, the median (or  other percentiles)  * may be ambiguous; choose the lower value.  For example, if there  are 200 objects   * and percentile = .5, return the 100th element.  *  *  @param   <T>  the type to find the percentile over (must implement  Comparable interface)  */ public   class  Percentile<T  extends  Comparable<T>>  implements  SummaryStatistic<T> { private   double   percent_m ; private  Sorter.sortType  sortChoice ; /**  * Creates a new Percentile object, with the percentile set as 
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: the parameter * percent and sorter algorithm of type sort. * @param percent the percentile of this summary statistic. */ public Percentile( double percent, Sorter.sortType sort) throws SequenceSummaryException { percent_m =percent; sortChoice =sort; //HOW DO YOU KNOW WHAT THE ARRAY IS? //Sorter s = new Sorter(sort); // TODO : implement me! //should this sort the array then calculate the value? } // TODO : is this just supposed to return the percent value? /** * * @return the percentile of this summary statistic instance. */ public double getPercentile() { return percent_m ; } //@Override public T getValue(T arr) throws SequenceSummaryException { double valueIndex; valueIndex= this .getPercentile()/100*arr. length ; if ((arr. length /2)%2==0) { valueIndex-=0.5; } return arr[( int )valueIndex]; } }...
View Full Document

Page1 / 2

Percentile - the parameter * percent and sorter algorithm...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online