



|
|
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:
- 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
|
|