/**
 *           BracketExample. Example(s) of the use of brackets in expressions and their
 *           effect on the order of operators.
 */

public class BracketExample {                  // Define class
    public static void main(String args[]) {  // Sart of main program

	//             Create 3 doubles a,b,c and setting their values

	double a = 10;
	double b = -12;
	double c = 14;

	
	double x = 5.0;

	//          Set y to the value of the quadratic   ax^2 + bx + c
	//          Note order of operators, so do NOT need brackets!!!
	
	double y = a*x*x + b*x + c;

	System.out.println("Value of first quadratic is " + y);
	
	//          Set y to    c(a + x)(b - x)  
	//          Need brackets to force the +/- operators to be evaluated first 

	y = c*(a + x)*(b - x);

	System.out.println("Value of second quadratic is " + y);

	//          Set y to        (a + x)(a - x)
	//                          --------------
	//                          (b + x)(b - x)
	//           
	//          Need an addition set of brackets rouned the denominator calculation
	//          to force (b+x)(b-x) to be calcualted as one unit. Note do NOT
	//          need brackets round (a+x)(a-x), why ??

	y = (a + x)*(a - x)/((b + x)*(b - x));

	System.out.println("Value of first quadratic fracton is " + y);


	//          What do you get if you DONT have the double brackets in the
	//          denominator.......

	y = (a + x)*(a - x)/(b + x)*(b - x);

	System.out.println("Value of puzzle is " + y);

    }
}
