import java.util.Scanner;

/**
 * A program that uses various Math methods.
 *
 * @author Mark Young (A00000000)
 */
public class MathMethods {

    public static void main(String[] args) {
        // create variables
        Scanner kbd = new Scanner(System.in);
        int n, m, big;
        int a, b, c;
        double x, y, z;

        // Introduce yourself
        System.out.println("\n\n"
                + "I'm just doin' some math!\n\n");
        pause();

        // Math.pow
        System.out.println("5 squared is " + Math.pow(5, 2));
        System.out.println("2 to the 5th is " + Math.pow(2, 5));
        pause();

        // Math.max
        System.out.print("Enter two integers: ");
        n = kbd.nextInt();
        m = kbd.nextInt();
        kbd.nextLine();
        big = Math.max(n, m);
        System.out.println("The maximum of " + m + " and " + n + " is "
                + big + ".");
        System.out.println("I wonder what the minimum is....");
        pause();

        // Math.sqrt
        x = Math.sqrt(10);
        System.out.println("The square root of 10 is " + x + ".");
        pause();

        // Math.hypot
        System.out.print("Enter two numbers (with decimals): ");
        y = kbd.nextDouble();
        z = kbd.nextDouble();
        kbd.nextLine();
        System.out.println("The diagonal of a rectangle of width " + y 
                + " and length " + z + " is " + Math.hypot(y, z) + ".");
        pause();


        // solve a quadratic equation
        System.out.print("Enter the a, b, and c co-ordinates "
                + "of a quadratic equation.\nFor example, "
                + "the 3, 5, and -1 in 3x^2 + 5x - 1: ");
        a = kbd.nextInt();
        b = kbd.nextInt();
        c = kbd.nextInt();
        kbd.nextLine();
        System.out.println("The roots of the equation "
                + a + "x^2 + " + b + "x + " + c + " are:\n\t"
                + ((-b + Math.sqrt(b*b - 4*a*c)) / (2 * a)) + " and \n\t"
                + ((-b - Math.sqrt(b*b - 4*a*c)) / (2 * a)) + ".");
        pause();

        // Math.round
        x = 3.6;
        m = (int)Math.round(x);
        System.out.println(x + " rounded off to the nearest int is " + m);
        System.out.print("Enter two numbers (with decimals): ");
        y = kbd.nextDouble();
        z = kbd.nextDouble();
        kbd.nextLine();
        n = (int)Math.round(y);
        m = (int)Math.round(z);
        System.out.println(y + " rounded off to the nearest int is " + n);
        System.out.println(z + " rounded off to the nearest int is " + m);
        x = 3456789012.34567890;
        m = (int)Math.round(x);
        System.out.printf("%,.1f rounded off to the nearest int is %,d.\n",
                x, m);
        System.out.println("\tor IS it????");
        pause();
    }

    /**
     * Prompt the user and wait for them to press the enter key.
     */
    public static void pause() {
        Scanner kbd = new Scanner(System.in);

        System.out.println();
        System.out.print("Press Enter...");
        kbd.nextLine();
        System.out.println();
    }

}
