



|
|
Byron's CSC212 Web Site
|
Programming Challenge Archive
Application Architecture
Functional 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 - Basic Application Architecture
// 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
Functional
*/
// Required Packages
// ---------------------------------------------------
import blue.io.*;
import blue.math.*;
import blue.shapes.*;
import java.lang.*;
// Application Class
// ---------------------------------------------------
class PercentWhiteApp
{
// Declare Variables
static private final int nrFaces = 6;
static private final int nrDots = 21;
// Main Method
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
// Other Methods
static private double readEdge()
{
IO.print("The Edge Length? ");
return IO.read_double();
}
static private double determineDiameter(double e+
dge)
{
return (edge/5);
}
static private double computeTotalArea(Square fa+
ce)
{
return (face.area() * nrFaces);
}
static private double computeBlackArea(Circle do+
t)
{
return (dot.area() * nrDots);
}
static private double computeWhiteArea
(double totalArea, double blackArea)
{
return (totalArea - blackArea);
}
static private double computeWhitePercent
(double totalArea, double whiteArea)
{
return ((whiteArea/totalArea) * 100);
}
// End of Other Methods
}
// 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.
*/
|
|
|