P Dunn's Super CS1 Site

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
P Dunn's Super CS1 Site  
 
 
Programming Challenge Archive

Lab Challenge Archive
Shapes Tasks Application
 
 
  Java Application  -- ShapesTasksApp

         // 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(p.degree());
                  IO.println();
  
               // Display the distance between far corners 
                  IO.print("The distance is ");
                  IO.print(r.diagonal());
                  IO.println();
  
               // Display the area of a pyramid
                  IO.print("The surface area is ");
                  double helperHeight = height;
          double helperWidth = s.diagonal() / 2.0;
          Rectangle helper = new Rectangle(helperHeight,help+
   erWidth);
          double triangleBaseSide = t.sideC();
          double triangleOtherSide = helper.diagonal();
          Triangle side = new Triangle(triangleBaseSide,tria+
   ngleOtherSide,triangleOtherSide);
          double surfaceArea = s.area() + (4*side.area());
          IO.print(surfaceArea);
                  IO.println();
  
               // Display the area of the scrap
                  
          // create the disk
          double diskSize = 5.0;
          Circle theDisk = new Circle(diskSize);
  
          // get the area of the circle
          double circleArea = theDisk.area();
          // display it
          IO.println("Disk area =" + circleArea);
  
          // get the area of the square
          double squareArea = s.area();
          //display it
          IO.println("Square area = " + squareArea);
  
          // subtract the area of the square from the area o+
   f the circle to get our scrap area
          double scrapArea = squareArea - circleArea;
  
                  IO.print("The area of the scrap is ");
  
          IO.print(scrapArea);
                  IO.println();
  
               // Display the area of a polygon
                  int newDegreeOfPolygon = (p.degree() * 2);
          
          double newSideOfPolygon = (p.side() * .5);
          Polygon newPolygon = new Polygon(newDegreeOfPolygo+
   n,newSideOfPolygon);
  
          IO.print("The area of the polygon is ");
          IO.print(newPolygon.area());
                  IO.println();
  
          IO.println("The degree of the new polygon is " + n+
   ewPolygon.degree());
          IO.println("The side length of the new polygon is +
   " + newPolygon.side()); 
  
               }
            }
  
  
         // Demo
         // -------------------------------------------------+
   -
  
         /*
  
   $ java ShapesTasksApp < ShapesTasksApp.data 
   |> 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 404.124962462459
   Disk area =78.53981633974483
   Square area = 196.0
   The area of the scrap is 117.46018366025517
   The area of the polygon is 798.1404177698992
   The degree of the new polygon is 16
   The side length of the new polygon is 6.3
   $ 
  
         */