Byron's CSC212 Web Site

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
Byron's CSC212 Web Site  
 
 
 
Class Notes

Monday September 18 , 2000
 
Rectangle Class  

 
  Class Notes  -- Monday September 18 , 2000

   
   CSC212 - September 18, 2000
   ======================================
  
   Lecture Topic: RECTANGLE CLASS
  
   Specification of the Rectangle Class
  
    Constructor - (<Length>,<Width>)
  
      new Rectangle (<double>,<double>) -> <rectangle>
  
    Operators
  
      <Rectangle>.length()    -> <double>
      <Rectangle>.area()      -> <double>
      <Rectangle>.perimeter() -> <double>
      <Rectangle>.diagonal()  -> <double>
      
    Commands
  
      <Rectangle>.display()   -> <double>
  
  
     Suppose we have a city block of length 480 and 
     width 300, partitioned into 16 rectangular lots
     as shown below.
        _______________________
       |  |  |  |  |  |  |  |  |
       |  |  |  |  |  |  |  |  |
       |__|__|__|__|__|__|__|__| 300
       |  |  |  |  |  |  |  |  |
       |  |  |  |  |  |  |  |  |
       |__|__|__|__|__|__|__|__|
                  480
  
   Tasks:
  
   1) Model the block and a lot in terms of rectangles.
  
      double blockLength = 480;
      double BlockWidth  = 300;
      Rectangle block = new Rectangle
                        (blockLength,blockWidth);
      double lotLength = blockLength / 8;
      double lotWidth = blockWidth / 2;
      Rectangle lot = new Rectangle (lotLength,lotWidth);
  
   2) Display the distance from opne corner of the block
      to the far corner.
  
      IO.println(block.diagonal());
  
   3) Declare a variable called PC and bind it to the 
      percent of the block taken up by one lot.
  
      double pc = (lot.area() / block.area())* 100;  
  
      // double pc - declare the variable 
      // = bind the variable
  
  
  
  
  
   DEF: 
  
  
  
  
  
  
  
  
  
      
  
  
  
  
  
        
  
  
  
  
   =========================================================
   123456789112345678921234567893123456789412345678951234567