public class Calculations
{
   public static void main(String[] args)
   {
      System.out.println("Rectangle");
      double width = 120;
      double length = 200;
      double area = width*length;
      double perimeter = 2*width + 2*length;
      System.out.println("Width     = " + width);
      System.out.println("Height    = " + length);
      System.out.println("Area      = " + area);
      System.out.println("Perimeter = " + perimeter);
      System.out.println("------------------------------");

      System.out.println("Triangle");
      double base = 12;
      double height = 5;
      double tArea = base * height / 2.0 ;
      double tPerim = base + height + Math.sqrt(base*base + height*height);
      System.out.println("Base      = " +  base);
      System.out.println("Height    = " + height);
      System.out.println("Area      = " + tArea);
      System.out.println("Perimeter = " + tPerim);
      System.out.println("------------------------------");

      System.out.println("Quadratic");
      double A = 2;
      double B = 8;
      double C = 6;
      double x1 = (-B + Math.sqrt(B*B-4*A*C))/(2*A);
      double x2 = (-B - Math.sqrt(B*B-4*A*C))/(2*A);
      System.out.println(A + "x\u00b2 + " + B + "x + " + C + " = 0 ");
      System.out.println("x1 = " + x1);
      System.out.println("x2 = " + x2);
      System.out.println("------------------------------");
   
      System.out.println("Sequences");      
      System.out.print("AP : ");
      int x = 2;
      for (int c=0; c < 10; c++)
      {
         System.out.print( x + "  ");
         x = x + 2;
      }
      System.out.println("");
      
      System.out.print("GP : ");
      x = 1;
      for (int c=0; c < 10; c++)
      {
         System.out.print( x + "  ");
         x = x * 2;
      }
      System.out.println("");

      System.out.print("Count Down : ");
      x = 10;
      for (int c=0; c < 11; c++)
      {
         System.out.print( x + "  ");
         x = x - 1;
      }
      System.out.println("");
      
      System.out.print("Halfs : ");
      x = 256;
      for (int c=0; c < 9; c++)
      {
         System.out.print( x + "  ");
         x = x / 2;
      }
      System.out.println("");
   }   
}


/***************************************************************
This program calculates the Area and Perimeter of a rectangle.
It is easy to change the width and length, then run the
program to recalculate for the new measurements.

(1) Find the Area of a rectangle with width = 120, length = 200
             
    -->  A = 24000   P = 640
(2) By experimenting (trying changing width and length)
    find the length and width that produce Area = 16 and Perimeter = 16

    -->  W = 4     L = 4

(3) Find the width and length for a rectangle with
    Area = 9 , Perimeter = 12.2

    -->  W = 3.6    L = 2.5
----------------------------------------------------------------
(4) Now write a program to calculate the Area and Permiter of
    a right-triangle, using the formulas:

      A = base * height / 2
                             _______________________________
      P = (base + height + \/ base * base + height * height

    Math.sqrt(9) = 3  calculates the square root of 9.

    (a) Find Area and Perimeter for base = 12 , height = 5
    
        A = 30    P = 30
    
    (b) By guessing, find values for base and height
        to make   area = 54 , perimeter = 36
        
        -->  base = 12   height = 9
        
----------------------------------------------------------------

(5) Write a program that calculates the Quadratic Formula:

     The ROOTS of the equation  Ax^2 + Bx + C = 0
     are given by:
                      __________________
               -B + \/ B*B - 4*A*C
         X1 =  ----------------------------
                        2*A

                      __________________
               -B - \/ B*B - 4*A*C
         X2 =  ----------------------------
                        2*A

    (a) Use the program to find the roots of   2x^2 + 8x + 6 = 0
    
        -->  x1 = -1   x2 = -3
    
    (b) Find the roots of   x^2 - 10x + 25 = 0
    
        -->  x1 = 5     x2 = 5
    
----------------------------------------------------------------

The second part of the program - the LOOP - prints a SEQUENCE.

(6) Write a program that prints each of the following sequences:

   (a)  2 , 4 , 6 , 8 , .... , 20   (AP)
   
   (b)  1 , 2 , 4 , 8 , .... , 1024  (GP)
   
   (c)  10 , 9 , 8 , 7 , .... , 1 , 0  (Count-down)
   
   (d)  256, 128 , 64 , 32 , .... , 4 , 2 , 1
              
****************************************************************/