



|
|
My Intro to Object-Oriented Programming
|
Programming Challenge Archive
Programming Assignment # 3
Basic Application Architecture
|
|
|
Read an edge length for a die. Determine the white percentage of the die if the black dots have a diameter equal to 1 / 5 the edge length of the die.
This version of Programming Assignment # 03 is written using the Basic Application Architecture.
JavaApplication - Programming Assignment # 3 --
Basic
// General Information
// ---------------------------------------------------
// File: PercentWhite.java
// Type: java application file
// Date: Wed Oct 18, 2000
// Name: Jeffrey R. Norkoli
// Line: Basic Application Architecture
// Application Description
// ---------------------------------------------------
/*
Read an edge length for a die. Determine the
white percentage of the die if the black dots
have a diameter equal to 1/5 the edge length
of the die.
This version of Programming Assignment #03 is
written using the Basic Application Architecture.
*/
// Required Packages
// ---------------------------------------------------
import blue.io.*;
import blue.shapes.*;
// Application Class
// ---------------------------------------------------
class PercentWhite
{
static public void main (String args[])
{
// Variable Declarations.
int nrFaces;
int nrDots;
double edge;
double diameter;
Square face;
double totalArea;
Circle dot;
double blackArea;
double whiteArea;
double percentWhite;
// Record number of sides of the die and the
// number of dots.
nrFaces = 6;
nrDots = 21;
// Read the side length of the die.
IO.print("Please enter the side length");
IO.print(" of the die: ");
edge = IO.read_double();
// Calculate the surface area of the die.
face = new Square(edge);
totalArea = face.area() * nrFaces;
// Calculate the surface area of the dots.
diameter = edge / 5.0;
dot = new Circle(diameter / 2.0);
blackArea = dot.area() * nrDots;
// Calculate the white area of the die.
whiteArea = totalArea - blackArea;
// Calculate the percentage of the die
// surface area that is white.
whiteArea = whiteArea / totalArea * 100;
// Print the result.
IO.print("The die is " + whiteArea);
IO.println(" percent white.");
}
}
// Demo
// ---------------------------------------------------
/*
$ javac PercentWhite.java
$ java PercentWhite
Please enter the side length of the die: 1.79
The die is 89.00442571243572 percent white.
$ java PercentWhite
Please enter the side length of the die: 5.43
The die is 89.00442571243572 percent white.
$
*/
|
|
|