function:RenderSidePart pageleftbodycaption pageleftbody sidenote Main.Aptest2009freresponse-SideNote Main.SideNote Site.SideNote

# Aptest2009freresponse

## Number one


public class NumberCube
{
/**@return and integer value between 1 and 6, inclusive
*/
public int toss()
{return (Math.random()*5)+1}

/** Returns an array of the values obtained by tossing a number cube numTosses
* times.
* @param cube a NumberCube
* @param numTosses the number of tosses to be recorded
*           Precondition: numTosses > 0
* @return an array of numTosses values
*/

public static int[] getCubeTosses (NumberCube cube, int numTosses)
{  int [] chocolate = new int [numTosses];
for (int g = 0; g< numTosses; g++0
chocolate [g] = cube.toss();
return chocolate;
}

/** Returns the starting index of the longest run of two or more consecutive
* repeated values in the array values
* @param values an array of integer values representing a series of number
* cube tosses
*       Precondition: values.length > 0
* @return the starting index of a run of maximum size;
*            -1 if there is no run
*/

public static int getLongestRun (int[] values)
{ int runDex = -1;
int runlong = 0;
int q,m;
for (int h = 0; h<values.length; h++)
{ q=h;
if (value[h] = value[h+1])
{ m=2;
while (value[q] = value [q+1])
{ m++;
q++;
}
if(m>rundex)
rundex = m;
}
}
return rundex;
}