/**
 * Main program that illustrates  mathematical expressions
 * to calculate common equations and to manipulate numeric digits
 */
public class FunWithMath
{
    public static void main(String[] args)
    {
        /**
         * Understanding integer division
         */

        // Consider this statement
        int intValue = 7 / 2;
        
        // What value will be printed?
        System.out.println("7 / 2 = " + intValue);
        
        // Consider this statement
        double doubleValue = 7 / 2;
        
        // What value will be printed?
        System.out.println("7 / 2 = " + doubleValue);
        
        // Consider this statement
        doubleValue = 7.0 / 2;
        
        // What value will be printed?
        System.out.println("7.0 / 2 = " + doubleValue);
        
        // Consider this statement
        doubleValue = 7 / 2.0;
        
        // What value will be printed?
        System.out.println("7 / 2.0 = " + doubleValue);
        
        System.out.println();
        
        /*
         * What data type should you be using when 
         * you need to perform accurate calculations?
         * 
         * Why is it important to use values like 7.0 or 2.0
         * in mathematical expressions?
         */
        
        /**
         * Computing some common geometric formulas
         */
       
        // Consider this variable
        double side = 12.6;
        System.out.println("side: " +  side);

        // What are we calculating and printing?
        double squareArea = side * side;
        System.out.println("area of square: " + squareArea);

        // What are we calculating and printing?
        double squareVolume = Math.pow(side, 3);
        System.out.println("volume of square: " +  squareVolume);        
        System.out.println();
        
        /**
         * What is Math.pow(side, 3) doing exactly?
         */
        
        // Consider these equations and output
        double a = 4;
        double b = 3;

        System.out.println("Side a = " + a);
        System.out.println("Side b = " + b);        
        
        double temp =  a * a + b * b;
        System.out.println("temp = " + temp);

        double h = Math.sqrt(temp);
        
        // What are we about to print?
        System.out.println("hypotenuse = " + h);
        System.out.println();
        
        /**
         * What is Math.sqrt(temp) doing exactly?
         */
       
        
        // Consider this constant
        final double pi = 3.14159;
        
        // Try to change the value of pi
      
        
        // Consider this varialble
        double r = 6.3;
        System.out.println("radius: " +  r);

        // What are we printing exactly?
        double circumference = 2 * pi * r;
        System.out.println("circumference: " + circumference);
 
        // What are we printing exactly?
        double circleArea = pi * r * r;
        System.out.println("area of circle: " + circleArea);        
        System.out.println();
        
        /**
         * How could we compute circle area using Math.pow?
         */
        

        
        // Consider this value:
        intValue = 13579;
        System.out.println("intValue = " + intValue);

        // What is number printed below?
        System.out.print( "Divide intValue by 10: ");
        System.out.println( intValue / 10 );

        // What is number printed below?
        System.out.print( "intValue modulus 10: ");
        System.out.println( intValue % 10);
        System.out.println();

        // Consider this value:
        int intValue2 = 5029;
        System.out.println("intValue2 = " + intValue2);       

        // What is number printed below?
        System.out.print( "Divide intValue2 by 50: ");
        System.out.println( intValue2 / 50 );

        // What is number printed below?
        System.out.print( "intValue2 modulus 50: ");
        System.out.println( intValue2 % 50);
        System.out.println();

        /**
         * In general what does the % do?
         */

        /**
         * Understanding floating-point (double) 
         * division and multiplication
         */        

        // Consider this value:
        doubleValue = 135.79;
        System.out.println("doubleValue = " + doubleValue);

        // What is number printed below?
        System.out.print( "Divide doubleValue by 10: ");
        System.out.println( doubleValue / 10 );

        // What is number printed below?
        System.out.print( "Divide doubleValue by 100: ");
        System.out.println( doubleValue / 100 );

        // What is number printed below?
        System.out.print( "Multiply doubleValue by 10:  ");
        System.out.println( doubleValue * 10);

        // What is number printed below?
        System.out.print( "Multiply doubleValue by 100: ");
        System.out.println( doubleValue * 100);
        System.out.println();
      

        // Consider this value:
        doubleValue = 135.79;
        System.out.println("doubleValue = " + doubleValue);

        // What is number printed below?
        int wholePart = (int) doubleValue;
        System.out.print( "wholePart: ");
        System.out.println( wholePart );
        
        // What is number printed below?
        doubleValue = doubleValue * 100;
        System.out.print( "doubleValue: ");
        System.out.println( doubleValue);
        
        
        int decimalPart = (int) doubleValue;
        System.out.print( "decimalPart: ");
        System.out.println( decimalPart);
        
        decimalPart = decimalPart % 100;
        System.out.print( "decimalPart: ");
        System.out.println( decimalPart);
        System.out.println();

         /**
         *  Breaking change into coins
         */

        // Consider this value:
        int change = 94;
        System.out.println("change = " + change);
        
        int quarters = change / 25;
        System.out.println("quarters = " + quarters);
        int remainder = change % 25;
        System.out.println("remainder = " + remainder);
        
        int dimes = remainder / 10;
        System.out.println("dimes = " + dimes);
        remainder = remainder % 10;
        System.out.println("remainder = " + remainder);
        
        int nickels = remainder / 5;
        System.out.println("nickels = " + nickels);
        int pennies = remainder % 5;
        System.out.println("pennies = " + pennies);
        
        System.out.println();

    }
}
