2009 Number Cube

<< 2010GridChecker | APQuestionsTrailIndex | 2009StockpileCritter >>

question

NumberCube.java


/**

 * @version 11 May 2009
 */
public class NumberCube 
{ 
  public NumberCube()
  {

  }
  /** 
   * toss
   * @return an integer value between 1 and 6, inclusive  
   */ 

  public int toss()  
  {  
      return 1+(int)(6*Math.random()); 
  } 
  /** 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)
  {
      //part a

  }
  /** Returns the starting index of a 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)
   {
       //part b:

    }

} 


NumberCubeTester.java


public class NumberCubeTester
{
	public static void main(String[]args)
	{
	    NumberCube c= new NumberCube();
	    int[] v= new int[18];
	    //part a test
	    v=c.getCubeTosses(c, 18);
	    System.out.println("The result from getCubeTosses:");
	    for(int i:v) System.out.print(i+" ");
	    System.out.println();
	    //part b test
	    int[] b = {1,5,5,4,3,1,2,2,2,2,6,1,3,3,5,5,5,5};
	    for(int i:b) System.out.print(i+" ");
	    System.out.println("\nLocation of longest run (should be either 6 or 14):");
	    System.out.println(c.getLongestRun(b));
	    System.out.println("\nLongest run of the random one:");
	    for(int i:v) System.out.print(i+" ");
	     System.out.print("\nis :");
	    System.out.println(c.getLongestRun(v));
	    int[] zilch = {1,2,3};
	     System.out.println("\nLongest run of zilch should be -1:");
	     System.out.println(c.getLongestRun(zilch));
	}
}