Byron's CSC212 Web Site

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
Byron's CSC212 Web Site  
 
 
Programming Challenge Archive

Application Architecture
Global Procedural Architecture
 
\subsubsubsection  

 
  JavaApplication  -- Percent White

   // General Information
   // ---------------------------------------------------
  
   // File:  DieAppGPAA.java
   // Type:  java application file
   // Date:  Mon Oct 23, 2000
   // Name:  Byron Bahr
   // Line:  Die Area - Global Procedural Applic Arch
  
   // Application Description
   // ---------------------------------------------------
  
   /*
      The "Standard Die" Area Problem
  
         This program finds the white area of a Die when 
         the Diameter of the Dots is 1/5 the Edge Length.
  
      Programming Approach
          
         The program will read a value corresponding to 
         n, the edge length of the Die.  It will compute
         the white area of the die and print it.
  
      Featured Application Architecture
  
         Global Procedural
   */
  
   // Required Packages
   // ---------------------------------------------------
      
      import blue.io.*;
      import blue.math.*;
      import blue.shapes.*;
      import java.lang.*;
  
   // Application Class
   // ---------------------------------------------------
      class DieAppGPAA
     {
      // Declare variables
  
      // Nr of Die Faces 
         static private final int nrFaces = 6;
      // Nr of Die Dots
         static private final int nrDots = 21;  
      // Define the diameter of a Dot
         static private double diameter;
      // Define the edge of the Die
         static private double edge;
      // Define the face of the Die
         static private Square face;
      // Define the Dots on the Die
         static private Circle dot;
      // Define the total area of the Die
         static private double totalArea;
      // Define the white area of the Die
         static private double whiteArea;
      // Define the black area of the Die
         static private double blackArea;
      // Define the percent white area of the Die
         static private double whitePercent;
  
      // The Main Method
         static public void main (String args[])
        { 
           establishDieDimensions();
           createFaceAndDot();
           computeAreas();
           computeWhitePercent();
           displayWhitePercent();
        }
  
      // Other Methods
         static private void establishDieDimensions()
        {
         // Enter the Die Dimensions
            IO.print("The Die Edge Length?  ");
            edge = IO.read_double(); 
        }
         static private void createFaceAndDot()
        {
         // Create the Die Face and Dot
            diameter = (edge / 5);
            face = new Square(edge);
            dot = new Circle(diameter/2);
        }              
         static private void computeAreas()
        {
         // Compute the Die Areas
            totalArea = face.area() * nrFaces;
            blackArea = dot.area() * nrDots;  
            whiteArea = totalArea - blackArea;
        }
         static private void computeWhitePercent()
        {
         // Compute the White Percentage
            whitePercent = (whiteArea / totalArea) * 100;
        }
          static private void displayWhitePercent()
        {
         // Print the White Percent of the Die
            IO.print("The Die is ");
            IO.print(whitePercent);
            IO.println(" percent white.");
         /*
            IO.println("The black area is " + blackArea);
            IO.println("The white area is " + whiteArea);
            IO.println("The total area is " + totalArea);
         */
      }
    }
   // Demo
   // ---------------------------------------------------
   /*
   The Die Edge Length?  1.79
   The Die is 89.00442571243572 percent white.
      
   The edge length?  5.43
   The Die is 89.00442571243572 percent white.
   */