/**************************************************
 * Loops contains some classic types of problems
 * involving loops
 *
 * @author Nancy Harris
 * @version V1 - 10/22/07
 *************************************************/
public class Loops
{
	/**********************************************
	 * multiply displays multiples of a number from
	 * 1 - 12
	 *
	 * @param inVal - The number to multiply
	 *********************************************/
	public void multiply(int inVal)
	{
		for (int ii = 1; ii <= 12; ii++)
		{
			System.out.println(inVal * ii);
		}
	}
	
	/*********************************************
	 * factorial calculates a number!
	 *
	 * @param inVal The number to calculate the factorial
	 * @return The factorial value
	 ********************************************/
	public int factorial(int inVal)
	{
		int result;
		result = 1; 
		
		for (int ii = 1; ii <= inVal; ii++)
		{
			result = result * ii;
		}
		return result;
	}
	
	/*********************************************
	 * sumRange calculates the sum of a range of numbers
	 *
	 * @param begin The low end of the range
	 * @param end The high end of the range
	 * @return Integer.MIN_VALUE if the begin < end else
	 *         returns the sum of the values in the range
	 *         inclusively
	 *********************************************/
	public int sumRange(int begin, int end)
	{
		int sum;
		sum = 0;
		
		if (begin < end)
			for (int ii = begin; ii <= end; ii++)
			{
				sum = sum + ii;
			}
		else
			sum = Integer.MIN_VALUE;	
		
		return sum;
	}
	
	/*********************************************
	 * sumFraction calculates the sum of a series 
	 * of fractions based on the incoming parameter
	 *
	 * @param inVal The incoming value
	 * @return The sum of the fractions in a series 
	 *         from 1/inVal, 2/inVal - 1 ... inVal/1.
	 *********************************************/
	public double sumFraction(int inVal)
	{
		double sum;
		sum = 0;
		
		for (int ii = 1; ii <= inVal; ii++)
		{
		//	System.out.println( inVal + " " + ii);
			
			sum = sum + (double) ii / (inVal - ii + 1);
			
		//	System.out.println(sum);
		}
		return sum;
	}// end sumFraction
}//end Loops