public class Calculate {
  /*  Constructor  */
  public Calculate() {
    
  }
  
  /*  returns the factorial of number.
   The call Calculate.fact(5) should return 120.  (1 * 2 * 3 * 4 * 5 = 120)
   */
  public static double fact(int number) {
    double product = 1;
    System.out.println("Product is initialized to " + product);
    // count from 1 to number
    System.out.println("i\tproduct");
    for (int i = 1; i <= number; i++) {
      product *= i;
      System.out.println(i + "\t" + product);
    }
    System.out.println("Final value of product is " + product);    
    return product;
  }
  
  /*  Outputs all of the divisors for number including 1 and the number
   The call Calculate.printAllDivisors(24) outputs 1 2 3 4 6 8 12 24
   */
  public static void printAllDivisors(int number) {
    
    for (int i = 1; i <= number; i++) {
      if ( number % i == 0 )
        System.out.print(i + " ");
    }
    System.out.println();
  }
  
  /*  returns true if the number is prime and false otherwise.
   A number is prime if is has no divisors except itself and 1.
   The smallest possible prime number is 2.
   The call Calculate.isPrime(5) returns true
   The call Calculate.isPrime(12) returns false
   */
  public static boolean isPrime(int number) {
    // take care of special cases before anything else
    if ( number < 2 )
      return false;
    for (int i = 2; i < number; i++) {
      if ( number % i == 0 )
        return false;
    }
    return true;
  }
  
  /*  returns the sum of all of the divisors except the number itself
   The call Calculate.sumOfProperDivisors(24) returns 36.
   1 + 2 + 3 + 4 + 6 + 8 + 12 = 36
   */
  public static int sumOfProperDivisors(int number) {
    int sum;
    sum = 0;
    for (int i = 1; i < number; i++) {
      // want to add divisors
      if ( number % i == 0 )
        sum += i;
    }
    return sum;
  }
  
  /*  returns true if the number is perfect and false otherwise.
   A perfect number is a number such that 
   the sum of its proper divisors equals the number
   The call Calculate.isPerfect(6) returns true because 1 + 2 + 3 = 6
   The call Calculate.isPerfect(10) returns false because 1 + 2 + 5 != 10
   */
  public static boolean isPerfect(int number) {
    int sum = Calculate.sumOfProperDivisors(number);
    boolean result = ( number == sum );
    return result;
  }
  
}