Return to Jeff's Main Page

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
My Intro to Object-Oriented Programming  
 
 
Programming Challenge Archive

Programming Assignment # 3
Functional Application Architecture
 
Read an edge length for a die.   Determine the white percentage of the die if the black dots have a diameter equal to 1 / 5 the edge length of the die. 

This version of Programming Assignment # 03 is written using the Functional Application Architecture.  

 
  JavaApplication - Programming Assignment # 3  -- Functional

   // General Information
   // ---------------------------------------------------
  
   // File:  PercentWhite.java
   // Type:  java application file
   // Date:  Wed Oct 18, 2000
   // Name:  Jeffrey R. Norkoli
   // Line:  Functional Application Architecture
  
   // Application Description
   // ---------------------------------------------------
  
   /*
      
      Read an edge length for a die.  Determine the 
      white percentage of the die if the black dots
      have a diameter equal to 1/5 the edge length
      of the die.
  
      This version of Programming Assignment #03 is
      written using the Functional Application
      Architecture.
   */
  
   // Required Packages
   // ---------------------------------------------------
  
      import blue.io.*;
      import blue.shapes.*;
  
   // Application Class
   // ---------------------------------------------------
  
      class PercentWhite
      {
         // Data local to PercentWhite.
         static private final int nrFaces = 6;
         static private final int nrDots = 21;
         
         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, whiteArea);
     IO.print("The die is ");
     IO.print(whitePercent);
     IO.println(" percent white.");
         }   // End of Main Method.
  
             // Read edge length of die.
                static private double readEdge()
                {
   IO.print("Please enter the side 
                        length of the die: ");
   return IO.read_double();
        }
  
             // Determine the diameter of a dot.
        static private double 
    determineDiameter(double edge)
        {
   return (edge / 5.0);
        }
  
             // Compute total area of die.
        static private double 
    computeTotalArea(Square face)
        {
   double ta = face.area() * nrFaces;
   return ta;
        }
  
     // Compute total area of black dots.
        static private double 
    computeBlackArea(Circle dot)
        {
   double dotArea = dot.area() 
       * nrDots;
   return dotArea;
        }
  
     // Compute total white area of die.
        static private double 
    computeWhiteArea(double totalArea, 
    double blackArea)
        {
   double wa = totalArea - blackArea;
   return wa;
        }
  
        // Compute total white area of die.
        static private double 
    computeWhitePercent(double 
    totalArea, double whiteArea)
        {
   double wp = whiteArea 
       / totalArea * 100;
   return wp;
        }
      }
  
   // Demo
   // ---------------------------------------------------
  
   /*
   $ javac PercentWhite.java
   $ java PercentWhite
   Please enter the side length of the die: 1.79
   The die is 89.00442571243572 percent white.
   $ java PercentWhite
   Please enter the side length of the die: 5.43
   The die is 89.00442571243572 percent white.
   $ 
   */