Return to Jeff's Main Page

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
My Intro to Object-Oriented Programming  
 
 
Programming Challenge Archive

Laboratory Challenges
Scripting with Shapes
 
This laboratory provided an exercise in creating and using objects.   In addition,  we got to equate the standard input file with a data file.  

 
  Laboratory Challenges  -- Scripting with Shapes

         // General Information
         // -------------------------------------------------+
   -
  
         // File:  ShapesTasksApp.java
         // Type:  java application file
         // Date:  Tue Oct 14, 1997
         // Name:  blue
         // Line:  Support for "Scripting with Shapes" Lab
  
  
         // Application Description
         // -------------------------------------------------+
   -
  
         /*
  
            Support for "Scripting with Shapes" Lab
  
         */
  
  
         // Required Packages
         // -------------------------------------------------+
   -
  
            import blue.io.*;
            import blue.shapes.*;
  
  
         // Application Class
         // -------------------------------------------------+
   -
  
            class ShapesTasksApp
            {
               static public void main (String args[])
               {
               // Read some numbers
   double squareSide = IO.read_double();
   double height = IO.read_double();
   double width = IO.read_double();
   double same = IO.read_double();
   double diff = IO.read_double();
   int degree = IO.read_int();
   double polySide = IO.read_double();
  
               // Establish shapes bindings
   Square s = new Square(squareSide);
   Rectangle r = new Rectangle(height,width);
   Triangle t = new Triangle(same,same,diff);
   Polygon p = new Polygon(degree,polySide);
                 
               // Establish shapes bindings
   s.describe();
   r.describe();
   t.describe();
   p.describe();
  
               // Display the number of sides of the polygon
                  IO.print("The polygon has degree:  ");
                  int ps = p.degree();
                  IO.println(ps);
  
               // Display the distance between far corners 
                  IO.print("The distance is ");
                  double diagonal = r.diagonal();
                  IO.println(diagonal);
  
               // Display the area of a pyramid
                  IO.print("The surface area is ");
                  double saPyramid = s.area() + 4 * t.area();+
  
                  IO.println(saPyramid);
  
               // Display the area of the scrap
                  IO.print("The area of the scrap is ");
          Circle ic = s.inscribingCircle();
                  double scrap = s.area() - ic.area();
                  IO.println(scrap);
  
               // Display the area of a polygon
                  IO.print("The area of the polygon is ");
                  Polygon newPoly = new Polygon(2*degree,poly+
   Side/2.0);
                  IO.println(newPoly.area());
  
               }
            }
  
  
         // Demo
         // -------------------------------------------------+
   -
  
         /* 
   $ javac ShapesTasksApp.java
   $ java ShapesTasksApp    |> Square with SIDE=14.0 <|
   |> Rectangle with HEIGHT=2.5 WIDTH=7.99 <|
   |> Triangle with SIDEA=29.5 SIDEB= 29.5 SIDEC= 14.0 <|
   |> Polygon with DEGREE=8 SIDE= 12.6 <|
   The polygon has degree:  8
   The distance is 8.371983038683249
   The surface area is 998.4088733307976
   The area of the scrap is 42.06195997410015
   The area of the polygon is 798.1404177698992
   $    
  
         */