CS1 Course Site

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
CS1 Course Site  
 
 
 
Wait , WAIT !!What's that word ? ( Class Notes ( without definitions ) )

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 >) 

Task
What is the area of the circle which ``circumscribes'' a square of side 11.5?
Picture (to help clerify ``circumscribes'')
Java code to perform this task...
double squareSide = 11.5;
Square s = new Square (squareSide);
double diagonalOfSquare = s.diagonal ();
double diameterOfCircle = diagonalOfSquare;
double radius = diameterOfCircle / 2;
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 blue area of the flag = the area of the flag - the area of the disk + the area of the inscribed square
< CLASS > ------ > BlueAndWhiteFlagApp
< NEEDS > ------ > import blue.shapes.   *;
< PROGRAMs > --- >
/ /Model the flag
double flagside = 3.0;
Square flag = new Square (flagSide);
/ /Model the disk
double diskDiameter = flagSide;
double radius = diskDiameter / 2;
Circle disk = new Circle (radius);
/ /Model the square
double helperSquareSide = flagSide / 2;
Square helper = new Square (helperSquareSide);
double smallSquareSide = helper.diagonal ();
Square smallSquare = new Square (smallSquareSide);
/ /Compute the foreground Area,  the middleground area,  and the background area
double fga = smallSquare.area ();
double mga = disk.area () - fga;
double bga = flag.area () - disk.area ();
/ /Compute the blue area
double blueArea = (flag.area () - disk.area ()) + smallSquare.area ();
/ /Display the result
IO.print ( ``The blue area is:   ``);
IO.print (blueArea);
IO.println ();
The triangle class
We will model a triangle in terms of its three sides.
Constructors
  • new Triangle (< double >) --- > < triangle > Equilateral
  • new Triangle (< double >,  < double >) --- > < triangle > Isosceles,  first the length of the sides.
  • new Triangle (< double >,  < double >,  < double >) --- > < triangle > irregular