Byron's CSC212 Web Site

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
Byron's CSC212 Web Site  
 
 
Programming Challenge Archive

Application Architecture
Object Oriented Architecture
 
\subsubsubsection  

 
  JavaApplication  -- Percent White

   // General Information
   // ---------------------------------------------------
  
   // File:  PercentWhiteApp.java
   // Type:  java application file
   // Date:  Mon Oct 23, 2000
   // Name:  Byron Bahr
   // Line:  Die Area - Object Oriented 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 an 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
  
         Object Oriented   
   */
  
   // Required Packages
   // ---------------------------------------------------
  
      import blue.io.*;
      import blue.math.*;
      import blue.shapes.*;
      import java.lang.*;
  
   // Application Class
   // ---------------------------------------------------
  
      class PercentWhiteApp
      {
       // The Main Method
          static public void main (String args[])
        {
          IO.println("Edge Length? "); 
          Die d = new Die(IO.read_double());
          IO.print("The Die is ");
          IO.print(d.whitePercent());
          IO.println(" percent white.");
        }
      }
          class Die
        { 
       // Instance Variables
          private double totalArea;
          private double blackArea;
          private double whiteArea;
        
       // Constructers
    
          public Die(double edge)
        {
       // Declare Given Information
          int nrFaces = 6;
          int nrDots = 21;
  
       // Define the radius of a Dot
          double diameter = edge/5;
  
       // Compute the area of a dot
          Circle dot = new Circle(diameter/2.0);
  
       // Compute the area of a Die Face
          Square face = new Square(edge);
  
       // Compute the total area of the Die faces
          totalArea = face.area() * nrFaces;
  
       // Compute the black area of the Die
          blackArea = dot.area() * nrDots;
  
       // Compute the white area of the Die
          whiteArea = totalArea - blackArea;
        }        
       // Define White Percent
          public double whitePercent()
        {
          return ((whiteArea/totalArea) * 100);   
        }
     }
   // 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.
   */