ENHANCED ``SHAPES WORLD'' FUNCTIONALITY CONTINUED
< Polygon > .circumscribingCircle () -- < Circle >
< Polygon > .inscribingCircle () -- < Circle >
< Circle > .circumscribingPolygon (< int >) -- < Polygon >
< Circle > .inscribingPolygon (< int >) -- < Polygon >
EXAMPLES
What is the area of the ``ring'' bounded by the inscribing circle and the circumscribing circle of a heptagon of side 25.2?
Polygon p = new Polygon (7, 25.2);
Circle ic = p.inscribingCircle ();
Circle cc = p.circumscribingCircle ();
double ringArea = cc.area () - ic.area ();
|
What is the area of the hexagon which inscribes a circle of diameter 50?
Circle c = new Circle (50.0 / 2.0);
Polygon x = c.inscribingPolygon (6);
double a = x.area ();
|
Some notes on character strings
The type ``string'' has the name string.
EXAMPLES
String animal1;
animal1 = ``zebra'';
String animal2 = ``fish'';
String wierdAnimal = animal1 + animal2;
IO.println (wierdAnimal);
|
THE ENVIRONMENT
animal1 -- ``zebra''
animal2 -- ``fish''
wierdAnimal -- ``zebrafish''
String s = IO.readString ();
|
Definition
An APPLICATION is a Java class containing a public static method called ``main.''
Definition
An APPLICATION ARCHITECTURE is a set of conventions regarding the components of an application and the communication among these components.
Definition
BASIC APPLICATION ARCHITECTURE is the application architecture in which teh application class contains precisely one thing, the main method.
PROBLEM
A line of n congruent squares collectively has area a. What is the perimeter of the line of squares?
SOLUTION
? Class -- lineOfSquaresBAA
? Program
/ /Declare some variables.
int nrSquares;
double figureArea;
double squareArea;
double squareSide;
int eeCount;
double perimeter;
/ /Read the data.
nrSquares = IO.read_int ();
figureArea = IO.read_double ();
/ /Compute the area of a square.
squareArea = figureArea /nrSquares;
/ /Compute side length of a square.
squareSide = Math.sqrt (squareArea);
/ /Compute the number of external edges.
eeCount = (2 * nrSquares) + 2;
/ /Compute the perimeter.
perimeter = eeCount * squareSide;
/ /Display the result.
IO.println (``Perimeter = ``+ perimeter);
|