/**
* Java program demonstrating the use of methods.
* @author (Michael Branicky), 09/12/06, 09/24/07
*/
public class MethodsDemo
{
   // class method that takes a double, x, as input and returns its log base 2
   public static double log2 (double x) {
     return Math.log(x)/Math.log(2.0);
   } 

   //   Given:  the lengths of two sides of a right triangle, a and b
   //  Return: the length of the hypotenuse
   public static double hypotenuse (double a, double b) {
     return Math.sqrt(a*a+b*b);
   } 

   // Returns: a random dice roll
   public static int rollDie () {
     return (int) (Math.random()*6.0)+1;
   } 

   // say goodbye
   //            indicates method doesn't return anything
   //            vvvv
   public static void signOff() {
     System.out.println("\nGoodbye!\n");
   }

   public static void main(String args[]) {
     // Variables to be used
     double y, a=-53., b, c, i;
     int roll1, roll2;

     // Test/use the log2 method
     y = log2(32.);
     System.out.println("The log base 2 of 32. is " + y);

     y = log2(128.);
     System.out.println("The log base 2 of 128. is " + y);

     // ------------------------------------------------------------------

     // Test/use the hypotenuse method
     c = hypotenuse(3.,4.);
     System.out.println("The hypotenuse of a 3., 4. right triangle is " + c);
     
     c = hypotenuse(5.,12.);
     System.out.println("The hypotenuse of a 5., 12. right triangle is " + c);     
     
     // ------------------------------------------------------------------

     // Test/use the rollDie method

     // roll a pair of dice
     roll1 = rollDie();
     roll2 = rollDie();
     System.out.println("Die 1 was a "+roll1+" and Die 2 was a "+roll2);
     
     // print out 10 dice rolls, separated by commas
     for (i=1; i<=9; i++) {
       System.out.print(rollDie()+", ");   // roll die repeatedly 
     }
     System.out.println(rollDie());        // tenth one, ended with newline

     // ------------------------------------------------------------------

     // Test/use the signOff method
     signOff();
   }
}
