CS1 Course Site

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
CS1 Course Site  
 
 
 
Class Notes

Wednesday September 20 , 2000
 

The Square Class

CONSTRUCTOR  

new Square (< double >) -- < square >  

OPERATORS  

< square > .side () -- < double >  

< square > .area () -- < double >  

< square > .perimeter () -- < double >  

< square > .diagonal () -- < double >  

COMMANDS  

< square > .describe ()  

< square > .expand (< double >)  

< square > .shrink (< double >)  

PROBLEM:  

What is the area of the circle which ``circumscribes'' a square of side 11.5?  

SOLUTION:  

  double squareSide = 11.5;
  Square s = new Square (squareSide);
  double diagonalOfSquare = s.diagonal ();
  double diameterOfCircle = diagonalOfSquare;
  double radius = diameterOfCircle / 2.0;
  Circle cc = new Circle (radius);
  IO.println (cc.area ());
 

PROBLEM:  

The design of a square flag is as follows:  

  • the background is blue
  • the middle is a white disk of maximal size,  minus the foreground
  • the foreground is a blue square which inscribes the disk
 

If the flag measures 3 feet on the side,  what is the blue area of the flag?  

The idea...the blue are of the flag = the area of the flag - the area of the disk + the area of the (small) square.  

SOLUTION:  

  ?   class -- BlueAndWhiteFlagApp
  ?   needs -- import blue.shapes.   *;
  ?   program
 
    / /Model the flag.
          double flagSide = 3.0;
          Square flag = new Square (flagSide);
 
    / /Model the disk.
          double diskDiamter = flagSide;
          double diskRadius = diskDiameter / 2.0;
          Circle disk = new Circle (diskRadius);
 
    / /Model the small square.
          double helperSquareSide = flagSide / 2.0;
          Square helper = new Square (helperSquareSide);
          double smallSquareSide = helper.diagonal ();
          Square smallSquare = new Square (smallSquareSide);
 
    / /Compute the blue area.
          double blueArea = flag.area () - disk.area () +
          smallSquare.area ();
 
    / /Display the results.
          IO.print (``The blue area is ``);
          IO.print (blueArea);
          IO.println ();
 

Charles Mingus on Creativity

Definition   IMAGINITIVE CONSTRUCTION is the problem solving strategy of idendtifying a key (essential) object,  not readily apparent in the problem description,  whose creation and manipulation renders the problem solution ``simpler.''