public class ThreeN_Helper
{ 

 
        // this method gets a number from the user  
   public int getNumber(String whichNumber)
  { 
     int number;
	   
	       // prompt for input	
     System.out.print (" Please enter the " + whichNumber + " number: ");

 			 // get user's input
	  number = Keyboard.readInt();

			// print a blank line
  	  System.out.println();

			// send user's input to calling method
     return number;       
  }	 
	  

       // this method checks to see if number has become 1
	public  boolean isNumberOne(int number)
	{  
	   final int ONE = 1;
	   boolean answer;     // holds boolean to be returned

		if (number == ONE)  
		  answer = true;
		else
		  answer = false;
		
		return answer;
	}
	
	     // this method echoes the input  
		  // prints the final results
		  // says "goodbye"
	public void printResults(int numberOne, int numberTwo, int sum)
	{
	   System.out.println (" The first number read was: " + numberOne);
	   System.out.println (" The second number read was: " + numberTwo);
	   System.out.println 
	     (" The sum of the cycle lengths of the numbers from " + 
	        numberOne + " to " + numberTwo + " is: " + sum);
      System.out.println ();
		    
			  //Output 2 tab characters immediately followed by 
			  //the String literal "3N + 1 problem completed"

	   System.out.println ( "\t\t3N + 1 Problem completed "	);
	}
	 
	     // this method determines whether number is odd or not
	 public boolean isOdd (int number)
	 {
	   final int TWO = 2;
		boolean answer;    // holds boolean value to be returned
		int temp;         // auxilliary variable to hold intermediate result
		
		temp = number % TWO;
		if ( temp == 0 )
		  answer = false;
		else
		  answer = true;
		
		return answer;
	 }
		
	 	 // this method computes cycle length
		 // it calls other methods within class to help it
	public int computeCycleLength (int number)
	{
	   boolean done;
		int count = 1;   // needs to start at 1 to count # itself
		int tempNumber ;  // holds copy of number which can be modified
								// without destroying the original number
		
	       // initialize copy
		tempNumber = number; 

			// initialize boolean used to control loop iteration
		done = false;  
		while ( !(done))
		{
		    if (isNumberOne (tempNumber)) // done
			   done = true;
		    else  // number is even or odd
			   {
				 if (isOdd(tempNumber)) 
				     tempNumber = 3 * tempNumber + 1;
				 else
				     tempNumber = tempNumber / 2;
			
             count ++;	// update counter because
				 				// another element of the cycle generated
				 }
		}		 
		return count;
   }
		
 	 		// this method prints the program heading
	public void  printHeader ()
	{
   	   //Print a single blank line.  
	 System.out.println ();
	 
        //Output 3 tab characters followed by the String literal 3N + 1 problem
	 System.out.println ("\t\t\t3N + 1 Problem");	  
	 
        //Print a single blank line.
    System.out.println ();
	}	
}		