import java.io.PrintWriter;
import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * Some simple Math tests.
 *
 * @author Samuel A. Rebelsky
 * @author Yvonne Palm
 * @author Jonathan Wellons
 */
public class MathStuff
{
  // +------+-----------------------------------------------------
  // | Main |
  // +------+

  public static void main(String[] args)
  {
    // Prepare input and screenput.
    BufferedReader keyboard = 
      new BufferedReader(new InputStreamReader(System.in));
    PrintWriter screen = new PrintWriter(System.out, true);

    // Create some interesting multipliable objects.
    MyInteger two = new MyInteger(2);
    Rational rat = new Rational(1,3);

    // Square the two values.
    screen.println(two + " squared is " + square(two));
    screen.println(rat + " squared is " + square(rat));

    // Compute values to the fifth power.
    screen.println(two + " raised to the fifth power is " + expt(two,5));
    screen.println(rat + " raised to the fifth power is " + expt(rat,5));

    // Multiply two by rat.
    screen.println(rat + "*" + two + " = " + rat.multiply(two));
    // That's it, we're done.
    System.exit(0);
  } // main(String[])

  // +----------------+-------------------------------------------
  // | Static Methods |
  // +----------------+

  /**
   * Square a multipliable number.
   */
  public static Multipliable square(Multipliable val)
  {
    return val.multiply(val);
  } // square(Multipliable)

  /**
   * Compute x^n for positive integer n.
   */
  public static Multipliable expt(Multipliable x, int n)
  {
    Multipliable result = x;
    for (int i = 1; i < n; i++) {
      result = result.multiply(x);
    }
    return result;
  } // expt(Multipliable,int)
} // class MathStuff
