



|
|
CS1 Course Site
|
Programming Challenge Archive
Application Architecture
Global Procedural Application Architecture
|
|
|
JavaApplication --
PercentWhite
// General Information
// ---------------------------------------------------
// File: percentWhite.java
// Type: java application file
// Date: Thu Oct 19, 2000
// Name: Kara Becker
// Line: Determine the percentage of white space on a die+
using the global procedural application architecture.
// Application Description
// ---------------------------------------------------
/*
Determine the percentage of white space on a die using t+
he global procedural application architecture.
*/
// Required Packages
// ---------------------------------------------------
import blue.io.*;
import blue.shapes.*;
// Application Class
// ---------------------------------------------------
class percentWhite
{
static public void main (String args[])
{
establishDieDimensions();
createFaceAndDot();
computeAreas();
computeWhitePercent();
displayWhitePercent();
}
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 private void establishDieDimensions()
{
edge = IO.read_double();
}
static private void createFaceAndDot()
{
diameter = (1.0 / 5.0) * edge;
face = new Square(edge);
dot = new Circle(diameter / 2.0);
}
static private void computeAreas()
{
totalArea = face.area() * nrFaces;
blackArea = (dot.area() * nrDots);
whiteArea = totalArea - blackArea;
}
static private void computeWhitePercent()
{
percentWhite = (whiteArea / totalArea) * 100.0;
}
static private void displayWhitePercent()
{
IO.println("The die is " + percentWhite + " percent white+
.");
}
}
// Demo
// ---------------------------------------------------
/*
$ javac percentWhite.java
$ java percentWhite
1.79
The die is 89.00442571243572 percent white.
$ javac percentWhite.java
$ java percentWhite
5.43
The die is 89.00442571243572 percent white.
$
*/
|
|
|