



|
|
CS1 Course Site
|
Programming Challenge Archive
Application Architecture
Basic Application Architecture
|
|
|
JavaApplication --
PercentWhite
// General Information
// ---------------------------------------------------
// File: percentWhite.java
// Type: java application file
// Date: Wed Oct 18, 2000
// Name: Kara Becker
// Line: Determine the percentage of white space on a die+
using basic application architecture.
// Application Description
// ---------------------------------------------------
/*
Determine the percentage of white space on a die using b+
asic application architecture.
*/
// Required Packages
// ---------------------------------------------------
import blue.io.*;
import blue.shapes.*;
// Application Class
// ---------------------------------------------------
class percentWhite
{
static public void main (String args[])
{
//Declare variables.
int nrSides;
double edgeLength;
double sideArea;
double dotArea;
double dieArea;
double totalDotArea;
double whiteDie;
double diameter;
//Record and read data.
nrSides = 6;
edgeLength = IO.read_double();
//Compute the area of the die.
Square s = new Square(edgeLength);
dieArea = s.area() * nrSides;
diameter = (1.0 / 5.0) * edgeLength;
//Compute the area of a dot.
Circle c = new Circle(diameter / 2.0);
dotArea = c.area();
//Compute the total area the dots take up.
totalDotArea = dotArea + (dotArea * 2) + (dotArea * 3) + +
(dotArea * 4) + (dotArea * 5) + (dotArea * 6);
//Determine the percentage of white space on the die.
whiteDie = ((dieArea - totalDotArea) / dieArea) * 100.0;
//Display the results.
IO.println("The die is " + whiteDie + " percent white.");+
}
}
// Demo
// ---------------------------------------------------
/*
$ javac whiteDie.java
$ java whiteDie
1.79
The die is 89.00442571243572 percent white.
$ javac whiteDie.java
$ java whiteDie
5.43
The die is 89.00442571243572 percent white.
$
*/
|
|
|