Return to Jeff's Main Page

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
My Intro to Object-Oriented Programming  
 
 
 
Class Notes

Wednesday September 27 , 2000
 
Class began with some additional constructors for the Polygon Class:
  • < Polygon > .circumscibingCircle () -- > < Circle >,  creates the circle circumscribing the given polygon
  • < Polygon > .inscibingCircle () -- > < Circle >,  creates the circle inscribing the given polygon
  • < Circle > .circumscibingPolygon (< int >) -- > < Polygon >,  creates the polygon circumscribing the given circle,  based on the number of sides of the polygon
  • < Circle > .inscibingPolygon (< int >) -- > < Polygon >,  creates the polygon inscribing the given circle,  based on the number of sides of the polygon
CG demonstrated the use of these new operators with a couple of quick examples.  

Some notes on character strings:

  • The type ``string'' has the name String.
  • To declare a string called ' animal' and bind it to ' zebra',  type:   String animal =  ``zebra'';
  • Reading a string:   String s = IO.readString ();
CG finished the session with an introduction to ' The Basic Application Architecture' and some Java code to demonstrate this architecture type.   The basic application architecture is the application architecture in which the application class contains precisely one thing,  the main method.   Here is an example: 


A line of n-congruent squares collectively has area a.   What is the perimeter of the line of squares? 

class LineOfSquaresBAA 

/ /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 one square. 

squareArea = figureArea /nrSquares; 

/ /Compute the sidelength of a square. 

squareSide = Math.sqrt (squareArea); 

/ /Compute the number of external edges. 

eeCount = 2 * nrSquares + 2; 

/ /Compute perimeter. 

perimeter = eeCount * squareSide; 

/ /Display result. 

IO.println (``Perimeter =  ``+ perimeter);