CS1 Course Site

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
CS1 Course Site  
 
 
Programming Challenge Archive

Program Potpouri
Shapes Tasks
 
This program was featured in the lab devoted to our experiences with the blue.shapes package.  

 
  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(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
            double sa = (t.area() * 4) + s.area();
    IO.print("The surface area is ");
    IO.print(sa);
            IO.println();
  
         // Display the area of the scrap
    Circle scrap = s.circumscribingCircle();
            IO.print("The area of the scrap is ");
            IO.print(scrap.area() - s.area());
            IO.println();
  
         // Display the area of a polygon
            IO.print("The area of the polygon is ");
    int newDeg = p.degree() * 2;
            double newSide = p.side()/2.0;
            Polygon newP = new Polygon(newDeg, newSide);
            IO.print(newP.area());
            IO.println();
  
         }
      }
  
  
   // 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 998.4088733307976
   The area of the scrap is 111.8760800517997
   The area of the polygon is 798.1404177698992
   $ 
   */