P Dunn's Super CS1 Site

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
P Dunn's Super CS1 Site  
 
 
 
Class Notes

Monday October 9 , 2000
 
Spec:
A program which features a circle class - just about like the blue.shapes.circle.class.   The program will need a real number corresponding to the radius of a circle,  create the circle and display its area and perimeter.  

Class Definition:  

  class CircleValuesApp
  {
  / /main method
  static public void main (String args [])
  {
  IO.println ( ``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 declaration
  double radius;
 
  / /constructor - instantiates an object
  public Circle (double x)
  {
  / /instantiate instance variables in constructor
  radius = x;
 
}  
  / /methods to implement behaviors
  public double area ()
  {
  return radius * radius * Math.PI;
 
}  
  public double perimeter ()
  {
  return 2 * radius * Math.PI;
 
}  
/ /end class}
 

Lab for 10 / 11 was discussed.   It was a good lab that did provide a degree of challenge.   See the Programming Archive for information on that lab and listing.  

Back to Application Architectures  

Definition   The GLOBAL PROCEDURAL APPLICATION ARCHITECTURE is the application architecture in which:

  1. All variables which appear anywhere within the class are declared local to the class and hence are global to all of the methods of the class.
  2. All methods defined in the class are commands.

 

Sketch of this architecture is in my paper notes.  

Notes:
1) Can't introduce variables in methods.
2) All variables are pre-defined.  

An operational procedure for writing an application consistent with the Global Procedural Application Architecture.

  1. Sketch a main method which hypothesizes the existence of commands which do what needs to be done.
  2. Add to (1) a ``data dictionary'' which associates variables with the concepts introduced in the main method.
  3. Define the commands hypothesized in the main method in such a way that they ``fit in'' with the data dictionary.
 

Once you have done this,  or as you are doing it,  place the code where it belongs in the program text.  

  class ---
  {
  / /data dictionary - (2)
 
  / /main method - (1)
 
  / /refined commands - (3)
 
}
 

Global Procedural Architecture for the ``line of squares'' problem we did in previous notes  

(1) The main method:
  static public void main (String args [])
  {
  readProblemParameters ();
  computeAreaOfOneSquare ();
  computeLengthOfOneSide ();
  computeNumberOfExternalEdges ();
  computePerimeter ();
  displayPerimeter ();
 
}
 

(2) The 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) Refind the commands in the context of # (1) and # (2).
  static private void readProblemParameters ()
  {
  IO.print ( ``Area of figure?   ``);
  figureArea = IO.read_double ();
  IO.print ( ``# of squares?   ``);
  nrSquares = IO.read_int ();
 
}  
  static private void computeAreaOfOneSquare ()
  {
  squareArea = figureArea /nrSquares;
 
}  
  static private void computeLengthOfSide ()
  {
  sideLength = Math.sqrt (squareArea);
 
}  
  static private void computerNumberOfExternalEdges ()
  {
  eeCount = (nrSquares * 2) + 2;
 
}  
  static private void computePerimeter ()
  {
  perimeter = eeCount * sideLength;
 
}  
  static private void displayPerimeter ()
  {
  IO.println ( ``Perimeter is ``+ perimeter);
 
}
 

1 main method and 6 other methods  

As a result of running...
1) readProblemParameters
the variables figureArea & nrSquares were bound  

As a result of running...
2) computeAreaOfOneSquare
the variable squareArea was bound  

and so on until the end of the program.