Synopsis
This class introduced us to another one of the shapes classes, the Square Class and how it can be used. Also introduced was another problem solving methodology called Imaginative Construction (defined below). The Triangle class was introduced near the end of the class as well.
|
The Square Class
(1) new Square (< double side length >) - > < Square >)
Operators
< Square > .side () - > < double >
< Square > .area () - > < double >
< Square > .perimter () - > < double >
< Square > .diagonal () - > < double >
Commands
< Square > .describe ()
< Square > .expand (< double >)
< Square > .shrink (< double >)
|
Task:
What is the area of the circle which ``circumscribes'' a square of side 11.5?
Java code to perform the task:
double squareSide = 11.5;
Square s = new Square (squareSide);
double diagonalOfSquare = s.diagonal ();
double diameterOfCircle = diagonalOfSquare;
double radius = diameterOfCircle / 2;
Circle cc = new Circle (radius);
IO.println (cc.area ());
|
Problem:
The design of a square flag is as follows.
- The background is blue.
- The middleground is a white disk of maximal size, minus the foreground.
- The foreground is a blue square which inscribes the disk.
If the flag measures 3 feet on the side, what is the blue area of the flag.
To solve A3 - Ac + Asq = Ablue
The blue area of the flag =
The area of the flag
- the area of the disk
+ the area of the (small) square
The Java:
Class > - > TheBlueAndWhiteFlagApp
Needs > - > import blue.shapes. *;
Program > - >
/ /Compute the area of the flag (mode)
double flagSide = 3.0;
Square flag = new Square (flagSide);
/ /Model the disk
double diskDiameter = flagSide;
double diskRadius = diskDiameter / 2;
Circle disk = new Circle (diskRadius);
/ /Model the small square
double helperSquareSide = flagSide / 2;
Square helper = new Square (helperSquareSide);
double smallSquareSide = helper.diagonal ();
Square smallSquare = new Square (smallSquareSide);
/ /Method 1
/ /Compute the foreground area
/ /The middleground area and the background area.
/ /fga = foregroundarea
double fga = smallSquare.area ();
double mga = diskArea () - fga;
/ /Method 2: preferred
double blueArea = flag.area () - disk.area () + smallSquare.area ();
/ /Display the result
IO.print ( ``The blue area is ``);
IO.print (blueArea);
IO.println ();
|
Definition
IMAGINATIVE CONSTRUCTION is the problem solving strategy of identifying a key (essential) object, not readily apparent in the problem description, whose creation and manipulation renders the problem solution ``simpler''.
What then was talked about were notes about the Shapes World Programming Challenge. Paper notes have tips in solving the problems here along with illustrative figures.
The Triangle Class
We will model a triangle in terms it's three sides.
Constructors
Equilateral triangle - new Triangle (< double >) - > < Triangle >
Isosceles triangle - new Triangle (< double >, < double >) - > < Triangle >
The first number is the length of 2 of the sides.
new Triangle (< double >, < double >, < double >) - > < Triangle >
|