



|
|
Byron's CSC212 Web Site
|
Programming Challenge Archive
Application Architecture
Basic Architecture
|
|
|
\subsubsubsection
JavaApplication --
Percent White
// General Information
// ---------------------------------------------------
// File: DieAppBAA.java
// Type: java application file
// Date: Mon Oct 23, 2000
// Name: Byron Bahr
// Line: Die White Area - Basic 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
Basic
*/
// Required Packages
// ---------------------------------------------------
import blue.io.*;
import blue.math.*;
import blue.shapes.*;
// Application Class
// ---------------------------------------------------
class DieAppBAA
{
static public void main (String args[])
{
//Define the given information
int nrFaces = 6;
int nrDots = 21;
//Read the edge length of the Die.
IO.print("The edge length? ");
double edge = IO.read_double();
// Define the diameter of a Dot.
double diameter = (edge/5);
// Define the Die Face.
Square face = new Square(edge);
// Compute the total area of the Die faces.
double totalArea = face.area()*nrFaces;
// Define the dot.
Circle dot = new Circle(diameter/2);
// Compute the total area of the Dots.
double blackArea = dot.area()*nrDots;
// Compute the white area of the Die.
double whiteArea =
(totalArea - blackArea);
// Compute the White Percent of the Die.
double whitePercent =
(whiteArea / totalArea) * 100;
// Print the White Percent of the Die
IO.print("The Die is ");
IO.print(whitePercent);
IO.println(" percent white.");
/*
IO.println("The black area is " + blackArea);
IO.println("The white area is " + whiteArea);
IO.println("The total area is " + totalArea);
*/
}
}
// 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.
*/
|
|
|