



|
|
P Dunn's Super CS1 Site
|
Programming Challenge Archive
Application Architectures
Basic Application Architecture
|
|
Java Application --
Basic App Arch
// General Information
// ---------------------------------------------------
// File: PercentWhite.java
// Type: java application file
// Date: Sun Oct 8, 2000
// Name: Patrick Dunn
// Line: A program to find the % of white on a die.
// Application Description
// ---------------------------------------------------
/*
This program will find the percentage of white contained+
on a standard die. This version is done using the
Basic Application Architecture
*/
// Required Packages
// ---------------------------------------------------
import blue.io.*;
import blue.shapes.*;
// Application Class
// ---------------------------------------------------
class PercentWhite
{
static public void main (String args[])
{
// read the side which will be used to calculate
// the dimensions of the die from the user
IO.print("Enter length of the edge of the die --> ");+
double sideSquare = IO.read_double();
// create the side
Square dieSide = new Square(sideSquare);
// get the area and multiply by 6 to get the area
// for all 6 sides
double cubeArea = (dieSide.area() * 6);
// calculate the radius of the dot to create it
// done by taking 1/5 of the user input
double dotDiameter = (.2 * sideSquare);
// create the dot
Circle dot = new Circle(dotDiameter/2.0);
double dotArea = dot.area() * 21;
// find the area - sub cubeArea - dotArea;
double area = cubeArea - dotArea;
// get the percentage
double percentageWhite = (area / cubeArea) * 100;
// display
IO.println("The percentage of die that is white is " ++
percentageWhite + " percent");
}
}
// Demo
// ---------------------------------------------------
/*
[patdunn@k6 basic]$ java PercentWhite
Enter length of the edge of the die --> 1.79
The percentage of die that is white is 89.00442571243572 p+
ercent
[patdunn@k6 basic]$ java PercentWhite
Enter length of the edge of the die --> 5.43
The percentage of die that is white is 89.00442571243572 p+
ercent
[patdunn@k6 basic]$
*/
|
|
|