CS1 Course Site

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
CS1 Course Site  
 
 
 
Class Notes

Wednesday September 13 , 2000
 

Lists and Hypertexh

Ordered Lists:
    beginol
    point (one)
    point (two)
    endol
 

Unordered Lists:
    beginul
    point (one)
    point (two)
    endul
 

Definition   CLASSIFICATION is the process of grouping objects having like properties (structure and behavior) into sets.

Definition   A CLASS is a set of objects grouped together as a result of classifications.

Definition   An INSTANCE of a class is an individual element of a class.

Definition   An OBJECT,  in the abstract,  is a collection of ``parts,  '' ``behaviors,  '' and ``relations.''

Definition   An OBJECT,  for practical programming purposes,  is either a class or an instance of a class.

Definition   A STATIC OBJECT is another term used to refer to a class.

Definition   A DYNAMIC OBJECT is another term used to refer to an instance of a class.

The Circle Class

Using ``shapes world,  '' a conceptual entity consisting of circles,  squares,  rectangles,  triangles,  and polygons,  we will create and use objects (also known as scripting).  

CIRCLE CLASS  

  newCircle (< double >) -- < circle >
  This program is used to create a new circle whose radius is the given number.
 
  < circle > .radius () -- < double >
  Compute the radius of the given circle.
 
  < circle > .diameter () -- < double >
  Compute the diameter of the circle.
 
  < circle > .area () -- < double >
  Compute the area of the circle.
 
  < circle > .perimeter () -- < double >
  Compute the perimeter of the circle.
 
  < circle > .describe ()
  Describes the circle.
 
  < circle > .expand (< double >)
  Increases the radius of the circle by the given number.
 
  < circle > .shrink (< double >)
  Decreases the radius of the circle by the given number.
 

TASKS:  

  Suppose c and d have been bound to circles.
 
  / /Display the area of circle c.
        IO.println (c.area ());
 
  / /Declare a variable called average and bind it to the
        average value of the radii of the two circles.
        double avg = (c.radius () + d.radius ()) / 2.0;
 
  / /Expand circle d by adding 10 to its radius.
        d.expand (10);
 
  / /Display the area of a circle of radius 15..
        Circle clara = new Circle (15);
        double areaOfClara = clara.area ();
        IO.println (areaOfClara);
 

Problem  

A circular garden of diameter 58.2 meters is surrounded by a 2 meter brick walkway.   What is the area of the walkway?  

This is the solution to the problem using problem decomposition and the circle class.  

  ?   class--WalkwayApp
  ?   needs--import blue.shapes.   *;
  ?   program
 
  / /Record the given information.
        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 (radiusOfXGarden);
 
  / /Compute the area of the walkway.
        double wwArea = xgarden.area () - garden.area ();
 
  / /Display the result.
        IO.print (``The area is ``);
        (wwArea);