CS1 Course Site

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
CS1 Course Site  
 
 
 
Wait , WAIT !!What's that word ? ( Class Notes ( without definitions ) )

Monday September 11 , 200
 
Solving the ``Perliminar'' problem by means of goal directed planning.
  • To determine the perimeter of the figure,  you need to know:
    • The length of a small square side
    • The number of such sides.
  • To determine the length of a small square side we need to know:
    • The area of the square.
  • To determine the area of one small sqare we need to know:
    • The number of a small square.
    • The total area of the figure
An approach to writing the program.
working in a ``Bottom-up'' fashion either
  • record an item of information,  or
  • compute a value.
Thus...
  • record the total area
  • record the number of small square
  • Compute the area of a small square
  • Compute the length of one side
  • record the number of small sides around the perimeter
  • Compute the perimeter
In Java
< CLASS > ---- > PerimeterApp.java
< PROGRAM >

/ /compose the perimeter
double totalArea = 187.32;
in nrSquares = 15;
double squareArea = totalArea /nrSquares;
double sideLength = Math.sqrt (squareArea);
int nrExternalSides = 20;
double perimeter = sideLength * nrExternalSides;
IO.print ( ``The perimeter is:   ``);
IO.print (perimeter);
IO.println ();
More on the Math class
  • Form:   Math.sqrt (< double >) -- > < double >
    meaning:   compute the square root of the parameters.
    Ex:   double value = Math.sqrt (16.0);
    value -- > 4.0
  • Form:   Math.PI -- > < double >;
    meaning:   Reference the classic greek consant.
    Ex
    double r = 5.8;
    double a = r * r * Math.PI;
    the area of a circle of radius 5.8

  • Math.pow (< double >,  < double >) -- > < double >
    meaning:   Raise the first value to the power of the second.
    Ex:   Math.pow (3.0,  2) = 9
        Math.pow (3,  4) = 81
        Math.pow (9,  0.5) = 3
        Math.pow (1000,  1 / 3.0) = 10
    cube root

    Note:   on Arithmatic
    < int > + < int > --- > < int >
    < double > + < double > --- > < double >
    < int > + < double > --- > < double >
    Similarly for *,  -,  / (divide)
    Ex
    IO.println (5 / 2) = 2
    IO.println (5.0 / 2.0) = 2.5 

    Lists in hypertexh
    ordered lists
    \\ beginol
    \\ point {one}
    \\ point {two}
    \\ point {three}
    \\ endul

    1. one
    2. two
    3. three
    \\ def{ GOAL DIRECTED PLANNING is...
    \\ beginol
    \\ point {identify...   }
    \\ point {Determine...   }
    \\ point {Establish...   }
    \\ point {Reevr....   }
    \\ endol
    }
    Unordered list
    \\ beginul
    \\ point {cat}
    \\ endul
    • cat