CS1 Course Site

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
CS1 Course Site  
 
 
 
Programming Challenge Archive

Shapes Tasks
 
 

 
  JavaApplication  -- ShapesTasks

   
   // 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.println(p.degree());
   IO.println();
  
   // Display the distance between far corners 
   IO.print("The distance is ");
   IO.println(r.diagonal());
   IO.println();
  
   // Display the area of a pyramid
   double sa = s.area()+(4*t.area());
   IO.print("The surface area is ");
   IO.println(sa);
   IO.println();
  
   // Display the area of the scrap
   s.inscribingCircle();
   IO.print("The area of the scrap is ");
   IO.println(s.area()-(s.inscribingCircle().area()));
   IO.println();
  
   // Display the area of a polygon
   Polygon newPoly = new Polygon((2*degree),(polySide/2));
   double areaPoly = newPoly.area();
   IO.println("The area of the polygon is " + areaPoly);
  
       }
   }
  
  
   // 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
     $     
   */