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
Global Procedural 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 Global Procedural Application Architecture.  

 
  JavaApplication - Programming Assignment # 3  -- Global

   // General Information
   // ---------------------------------------------------
  
   // File:  PercentWhite.java
   // Type:  java application file
   // Date:  Wed Oct 18, 2000
   // Name:  Jeffrey R. Norkoli
   // Line:  Global Procedural 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 Global Procedural
      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 private double edge;
         static private double diameter;
         static private Square face;
         static private Circle dot;
         static private double totalArea;
         static private double whiteArea;
         static private double blackArea;
         static private double percentWhite;
  
         static public void main (String args[])
         {
         // Main method.
    establishDieDimensions();
    createFaceAndDot();
    computeAreas();
    computeWhitePercent();
    displayWhitePercent();
         }
  
            // Establish the die dimensions.
       static private void 
   establishDieDimensions()
       {
   IO.print("Please enter the side 
                        length of the die: ");
   edge = IO.read_double();
       }
       
            // Create the die face and the dots.
               static private void createFaceAndDot()
               {
   face = new Square(edge);
   diameter = edge / 5.0;
   dot = new Circle(diameter / 2.0);
       }    
         
            // Compute areas of die face and dots.
       static private void computeAreas()
       {
   totalArea = face.area() * nrFaces;
   blackArea = dot.area() * nrDots;
   whiteArea = totalArea - blackArea;
       }
  
            // Compute the white area percentage 
            // of the die.
       static private void computeWhitePercent()
       {
   percentWhite = whiteArea 
       / totalArea * 100;
       }
  
            // Display the results.
       static private void displayWhitePercent()
       {
   IO.println("The die is " + 
      percentWhite + " percent white.");
       }
      }
  
   // 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.
   $ 
   */