



|
|
CS1 Course Site
|
Wait , WAIT !!What's that word ? ( Class Notes ( without definitions ) )
Monday September 25 , 2000
|
|
Operators
< triangle > .sideA () ------- > < double >
< triangle > .sideB () ------- > < double >
< triangle > .sideC () ------- > < double >
< triangle > .area () -------- > < double >
< triangle > .perimeter () --- > < double >
Command
< triangle > .display ()
Example
- Display the area of a triangle of sides 5, 6.2 and 9.58.
Triangle t = new Triangle (5, 6.2, 9.58);
IO.println (t.area ());
- Compute the area of the ``house'' which is the icon on your website for going to the root page of the site assuming that a variable named s is bound to the square which is its frame.
Triangle roof = new Triangle (s.side ());
double houseArea = s.area () + roof.area ();
A ``real'' problem involving triangles.
A pyramid with a square base measures 24.5 feet oer sude at the base. It stands 92.4 ft at its high point. What is the surface area?
To solve this problem we can use problem decomposition.
The surface area equals the area of the base plus four times the area of a side.
Computing the area of the base is easy.
Computing the area of a side is more challening.
< PROGRAM > --- >
/ /Record given information
double pyramidHeight = 92.4;
double baseSide = 24.5;
/ /Create base
Square base = new Square (baseSide);
/ /Create a side - by means of ``an imaginative constrution''
double helperHeight = pyramidHeight;
double helperWidth = base.diagonal () / 2;
Rectang; e helper = new Rectangle (helperHeight, helperWidth);
double triangleBaseSide = baseSide;
double triangleOtherSide = helper.diagonal ();
/ /Create pyramid side
Triangle side = new Triangle (baseSide, triangleOtherSide, triangleOtherSide);
/ /Compute the total surface area
double sa = base.area () + (4 * side.area ());
/ /Display result
IO.print ( ``The surface area is: ``);
IO.print (sa + ``square feet'');
IO.print ();
Polygons
A polygon will be modeled in terms of two properties:
- Degree - number of sides
- Side - length of the sides
Co-constructor
new Polygon (< int >, < double >) --- > < polygon >
Operators
< polygon > .degree () ---- > < int >
< polygon > .side () ------ > < double >
< polygon > .perimeter () - > < double >
< polygon > .area () ------ >
Command
< polygon > .display ()
Example tasks
- Display the area of a stop sign of side 2.0 feet
Polygon stopSign = new Polygon (8, 2.0);
IO.println (stopSign.area ());
Task A
double squareside = IO.read_double ();
Task B
Square s = new Square (squareSide);
Rectangle r = -------------------
_ _ _ _ _
-----
Enhanced ``shape world''
Functionality
< square > .circumscribingCircle () --- > < circle >
< square > .inscribingCircle () ------- > < circle >
< circle > .circumscribingSquare () --- > < square >
< circle > .inscribingSquare () ------- > < square >
|
|