Return to Jeff's Main Page

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
My Intro to Object-Oriented Programming  
 
 
 
Class Notes

Wednesday September 13 , 2000
 
CG jumped right into numerous definitions:   classification,  class,  instance of a class,  object,  static object,  and dynamic object.  

After the list of definitions,  CJ introduced us to the Circle Class.   The idea of using the Circle Class is to acquaint us with the creation and use of objects.   The Circle Class is part of a larger conceptual entity called the ``Shapes World'',  which includes circles,  squares,  rectangles,  and polygons.  

Here's a list of all the things we can do with circles:

  • new Circle (< double >) -- > < Circle >,  creates a circle whose radius is the given number
  • < Circle > .radius () -- > < double >,  computes the radius of the circle
  • < Circle > .diameter () -- > < double >,  computes the diameter of the circle
  • < Circle > .area () -- > < double >,  computes the area of the circle
  • < Circle > .perimeter () -- > < double >,  computes 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
To get the shapes class:   import blue.shapes.   *;  

Here is a problem using the Circle Class:
 

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

class WalkWayApp 

import blue.shapes.   *; 

/ /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 ``extended'' garden. 

double radiusOfXGarden = (radiusOfGarden + walkwayWidth);
Circle xgarden = new Circle (radiusOfXGarden); 

/ /Compute the area of the walkway. 

double walkwayArea = xgarden.area () - garden.area (); 

/ /Display result. 

IO.print (``The area is ``);
IO.println (walkwayArea);