Byron's CSC212 Web Site

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
Byron's CSC212 Web Site  
 
 
Programming Challenge Archive

Program Potpouri ( Lab Programming )
Shapes Tasks
 
This program from Lab # 4 demonstrates creating and using objects.  

 
  JavaApplication  -- Shapes Tasks

         // 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:  ");
              IO.print (degree);
              IO.println();
  
         // Display the distance between far corners  
              IO.print("The BFC distance is ");
              double diagonalOfRectangle=r.diagonal();
              IO.print(diagonalOfRectangle);
              IO.println();
  
         // Display the surface area of a pyramid
              IO.print("The surface area is ");
              IO.print(s.area() + (4*t.area()));
              IO.println();
  
         // Display the area of the scrap
              IO.print("The area of the scrap is ");
              IO.print(s.area()-s.inscribingCircle().area());+
  
              IO.println();
  
         // Display the area of a polygon
              Polygon p2 = 
                    new Polygon((2*degree),(polyside/2)); 
              double polygonArea=(p2.area());
  
              IO.print("The area of the polygon is ");
              IO.print(polygonArea);
              IO.println();
  
               }
            }
  
  
         // Demo
         // -------------------------------------------------+
  
  
         /*
      |> 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 BFC 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
         */