CS1 Course Site

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

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

Tuesday October 10 , 2000
 
A program which features a Circle class - just about like the blue.shapes Circle class.   The program will read a real number corrisponding to the radius of a circle,  the circle,  and display its area and perimeter.
Class CircleValuesApp
{
/ /main method
    static public void main (---)
    {
        IO.print ( ``Radius?   '' );
        double r = IO.read_double ();
        Circle c = new Circle (r);
        IO.println ( ``Area =  ``+ c.area ());
        IO.println ( ``Perimeter =  ``+ c.perimeter ());
    }
    class Circle
    {
    / /Instance variables
        double radius;
    / /Constructor
        public Circle (double x)
        {
            radius = x;
        }
        / /Methods
            public double area ()
            {
                return (radius * radius * Math.PI)
;              }
             public double perimeter ()
             {
                 return (2 * radius * Math.PI);
             }
         }
     }
     / /Commands
         static private void readBy____D____ ()
         {
             height = -------;
             diameter = ------ '
         }
         The parameter list will be like (Cicle bot,  double h)
         What must you do in the body of this operator?
         {
             Create + return a rectangle
         }
 }
 

Global procedural Architecture for the ``Line of Squares''

  1. The main method
    static void main (----)
    {
        readProblemParameters ();
        computeAreaOfOneSquare ();
        computeNumberOfExternalEdges ();
        computePerimeter ();
        displayPerimeter ();
    }

  2. Data Dictionary
    static private double figureArea;  static private int nrSquares;  static private double squareArea;  static private double sideLength;  static private int eeCount;  static private double perimeter;
  3. Refine the commands in the context of # 1 and # 2.
    static private void readProblemParameters ()
    {
        IO.print ( ``Area of figure?   ``);
        figureArea = IO.read_double ();
        IO.print ( ``Nr of squares?   ``);
        nrSquares = IO.read_int ();
    }
    static private void computeAreaOfOneSquare ()
    {
        squareArea = (figureArea /nrSquares);
    }
    static private void computeLengthOfSide ()
    {
        sideLength = Math.sqrt (squareArea);
    }