CS1 Course Site

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
CS1 Course Site  
 
 
Programming Challenge Archive

Application Architecture
Functional Application Architecture
 
 

 
  JavaApplication  -- PercentWhite

   // General Information
   // ---------------------------------------------------
  
   // File:  percentWhite.java
   // Type:  java application file
   // Date:  Sun Oct 22, 2000
   // Name:  Kara Becker
   // Line:  Determine the percentage of white space on a die+
    using functional application architecture.
  
   // Application Description
   // ---------------------------------------------------
  
   /*
     Determine the percentage of white space on a die using f+
   unctional application architecture.
   */
  
   // Required Packages
   // ---------------------------------------------------
  
   import blue.io.*;
   import blue.shapes.*;
  
   // Application Class
   // ---------------------------------------------------
  
   class percentWhite
   {
       static public void main (String args[])
       {
   double edge = readEdge();
   double diameter = determineDiameter(edge);
   Square face = new Square(edge);
   Circle dot = new Circle(diameter/2.0);
   double totalArea = computeTotalArea(face);
   double blackArea = computeBlackArea(dot);
   double whiteArea = computeWhiteArea(totalArea,blackArea);+
  
   double whitePercent = computeWhitePercent(totalArea,white+
   Area);
   IO.print("The die is ");
   IO.print(whitePercent);
   IO.println(" percent white.");
       }
       
       static private final int nrFaces = 6;
       static private final int nrDots = 21;
       
       static private double readEdge()
       {
   IO.print("The edge is? ");
   return IO.read_double();
       }
       
       static private double determineDiameter(double edge)
       {
   double diameter = edge * (1.0 / 5.0);
   return diameter;
       }
       
       static private double computeTotalArea(Square face)
       {
   double ta = face.area() * nrFaces;
   return ta;
       }
       
       static private double computeBlackArea(Circle dot)
       {
   double ba = dot.area() * nrDots;
   return ba;
       }
       
       static private double computeWhiteArea(double totalAre+
   a,double blackArea)
       {
   return totalArea - blackArea;
       }
       
       static private double computeWhitePercent(double total+
   Area,double whiteArea)
       {
   return (whiteArea / totalArea) * 100.0;
       }
   }
  
  
   // Demo
   // ---------------------------------------------------
  
   /*
     $ javac percentWhite.java
     $ java percentWhite
     The edge is? 1.79
     The die is 89.00442571243572 percent white.
     $ javac percentWhite.java
     $ java percentWhite
     The edge is? 5.43
     The die is 89.00442571243572 percent white.
     $
   */