Synopsis
This class introduces us to the basics object oriented programming and it also introduced us to the blue.shapes.Circle classes and how they can be used to solve various problems. A problem was defined and solved utilizing the shapes class.
|
Also talked about were additional tags for Hypertexh including lists, ordered and unordered.
Definition
CLASSIFICATION is the process of grouping objects having like properties (structural and behavior) into sets.
Definition
A set of objects grouped together as a result of classification is called a CLASS .
Definition
An individual element of a class is referred to as an INSTANCE of the class.
Definition
An OBJECT, in the abstract, is a collection of ``parts'', ``behaviors'', and ``relations''.
Definition
For practical programming purposes, an OBJECT is either a class or an instance of a class.
Definition
A class is sometimes referred to as a STATIC OBJECT .
Definition
An instance of a class is sometimes referred to as a DYNAMIC OBJECT .
REMARK
As an activity to aquaint us with the creation and use of objects (i.e. scripting) we will solve a collection of problems posed in the context of a ``shapes world''.
``Shapes World'' - a conceptual entity consisting of circles, squares, rectangles, triangles, and polygons. - A realm in which interesting computations on shapes abound.
The Circle class
We will model a circle in terms of one number; its radius and the following programs:
- > new Circle (< double >) - > < circle > (new instance)
- This program is used to create a new circle whose radius is the given number.
- > new < circle > .radius () - > < double >
- Compute the radius of the given circle.
- > new < circle > .diameter () - > < double >
- Compute the diameter of the given circle.
- > new < circle > .area () - > < double >
- Compute the area of the given circle.
- > new < circle > .perimeter () - > < double >
- Compute the perimeter of the given circle.
- > new < circle > .describe () - > < double >
- > new < circle > .expand (double)
- Increases the radius of the circle by the given number.
- > new < circle > .shrink (double)
- Decrease the radius of the circle by the given number.
Tasks
Suppose c and d have been bound to cirlces.
1) Display the area of circle c.
IO.println (c.area ());
2) Declare a variable called avg and bind it to the average value of the radii of the two circles.
double avg = (c.radius () + d.radius ()) / 2.0;
3) Expand circle d by adding 10 to it's radius
d.expand (10);
4) Display the area of a circle of radius 15.
/ /create instance of circle
Circle clara = new Circle (15);
double areaOfClara = areaOfClara.area ();
IO.println (areaOfClara);
|
Notes
Circle is a
class.
Clara is an
instance
of class Circle.
IO is a
class.
15 is a ``primitive atomic type'' - can't send a message to it.
Area is an
instance
method - associated w /clara.
Println is a
static
method - associated w /class so it's static.
Problem
A circular garden of diameter 58.2 meters is surrounded by a 2 meter brick walkway. What is the area of the walkway?
To solve this we will use
Problem Decomposition.
class > - > WalkwayApp
needs > - > import blue.shapes. *;
progra > - >
/ /Record the given info
double diameterOfGarden = 58.2;
double walkwayWidth = 2.0;
/ /Create the garden
double radiusOfGarden = (diameterOfGarden / 2.0);
Circle garden = new Circle (radiusOfGarden)
;
/ /Create the ``extended garden''
double radiusOfXGarden = (radiusOfGarden + walkwayWidth);
Circle xGarden = new Circle (radius of xGarden);
/ /Compute the area of the walkway
double WalkwayArea = xGarden.area () - garden.area ();
/ /Display the result
IO.print ( ``The area is: ``);
IO.println (walkwayArea);
|