CS1 Course Site

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
CS1 Course Site  
 
 
Programming Challenge Archive

Application Architectures
Basic Application Architecture
 
The Problem :   A ``standard'' die measures some number of inches on the edge.   Its spots measure one /fifth the edge length on the diameter.   What percent of the die is white?   Write a program to solve the problem in a manner consistent with the basic application architecture.   Run the program twice.   Enter the values 1.79 and 5.43 as data on the successive runs.
 
  JavaApplication  -- Basic Application Architecture

   // General Information
   // ---------------------------------------------------
  
   // File:  PercentWhite.java
   // Type:  java application file
   // Date:  Tue Oct 24, 2000
   // Name:  James W. Bremenour
   // Line:  Calculates the percent of white of a die
  
   // Application Description
   // ---------------------------------------------------
  
   /*
      Calculates the percentage of white visible on a 
      "standard" die.
   */
  
   // Required Packages
   // ---------------------------------------------------
  
      import blue.io.*;
      import blue.shapes.*;
  
   // Application Class
   // ---------------------------------------------------
  
      class PercentWhite
      {
         static public void main (String args[])
         {
          // Establish the known values
     int nrDots = 21;
     int nrSides = 6;
     double edge = IO.read_double();
     double diameter = edge/5.0;
          // Create aspects of the die
     Circle dot = new Circle(diameter/2.0);
     Square oneSide = new Square(edge);
          // Calculate areas
     double dotArea = dot.area() * nrDots;
     double totalArea = oneSide.area() * nrSides;
     double whiteArea = totalArea - dotArea;
          // Calculate white percentage
     double whitePrcnt = 
         (whiteArea/(totalArea))*100;
          // Display the white percentage
     IO.print("The die is: " + whitePrcnt);
     IO.print("% white");
     IO.println();
         }
      }
  
   // Demo
   // ---------------------------------------------------
  
   /*
   $ java PercentWhite
   1.79
   The die is: 89.00442571243572% white
   $ java PercentWhite
   5.43
   The die is: 89.00442571243572% white
   $ 
   */