Byron's CSC212 Web Site

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
Byron's CSC212 Web Site  
 
 
 
Class Notes

Monday September 25 , 2000
 
Operators,  Commands & Constructors  

 
  Class Notes  -- Monday September 25 , 2000

   
   CSC212 - September 25, 2000
   ======================================
  
   Lecture Topic: TRIANGLE CLASS
  
   Triangle Class: We will model the triangle in terms
                   of its three sides.
  
    Constructors
  
      Equallateral Triangle:
  
        new Triangle (<double>) -> <Triangle>
  
      Isocoles Triangle:
  
        new Triangle (<double>,double>) -> <Triangle>
  
        The first number is the length of 2 of the sides.
  
      Triangle:
  
        new Triagnle (<double>,<double>,<double>)
             -> <triangle>                                  
  
    Operators
  
       <Triangle>.sideA()     -> <double>
  
       <Triangle>.sideB()     -> <double>
  
       <Triangle>.sideC()     -> <double>
  
       <Triangle>.area()      -> <double>      
  
       <Triangle>.perimeter() -> <double>
  
    Commands
  
       <Triangle>.display()   -> <double>
  
  
   Ex: 
  
   1) Display the area of a triangle of sides 5, 6.2, 9.58.
  
       Triangle t = new Triangle(5,6.2,9.58);
       IO.println(t.area());
  
   2) Compute the area of the "House" which is the Icon on 
      your website for going to the "root-page" of the site
      assuming that the variable named "s" is bound to the 
      square which is its frame.
  
               /\
              /  \
             /____\
             |    | 
             |____|
  
  
    Triangle roof = new Triangle (s.side());
    double houseArea = s.area() + roof.area();
  
  
   A Real problem - Involving Triangles
  
    A pyramid with a square base measures 24.5 feet per 
    side, at the base.  It stands 92.4 feet at it's high
    point.  What is the surface area of the pyramid?
  
    To solve the problem, we can use Problem Decomposition.
  
    The surface area equals the area of the base plus four 
    times the area of a side.
  
    Computing the area of the base is easy - square base.
  
    Computing the area of a side is more challenging. We
    can do so using imaginative construction.
  
  
   Polygons
  
    A polygon will be modeled in terms of two properties.
  
      degree = nr of sides
      side   = length of side
    
    Constructors
  
      new Polygon (<int>,<double>) -> <Polygon>
  
         // int = nr of Sides
         // double = length of side
       
    Operators
  
      <Polygon>.degree()    -> <int>   
  
      <Polygon>.side()      -> <double>
  
      <Polygon>.perimeter() -> <double>
  
      <Polygon>.area()      -> <double>
  
    Commands
  
      <Polygon>.display()
  
   Example Tasks
  
   1) Display the area of a stop sign of side 2 feet
  
      <?Program>
       
       Polygon stopSign = new Polygon(8,2.0)
       IO.println (stopSign.area());
  
  
  
   =========================================================
   123456789112345678921234567893123456789412345678951234567