



|
|
My Intro to Object-Oriented Programming
|
Programming Challenge Archive
Programming Assignment # 1
Column of Cubes
|
|
|
A structure is constructed by adjoining 5 cubes into a column. The external surface area of the structure is 587.785 SF. Find the volume of the structure. Note: it is assumed that the ``top horizontal'' face of this column is included in the surface area given.
JavaApplication - Programming Assignment # 1 --
Column of Cubes
// General Information
// ---------------------------------------------------
// File: ColumnOfCubesApp.java
// Type: java application file
// Date: Mon Sep 18, 2000
// Name: Jeffrey R. Norkoli
// Line: Find the volume of a column made of cubes.
// Application Description
// ---------------------------------------------------
/*
A structure is constructed by adjoining 5 cubes
into a column. The external surface area of the
structure is 587.785 SF. Find the volume of the
structure. Note: it is assumed that the "top
horizontal" face of this column is included in the
surface area given.
*/
// Required Packages
// ---------------------------------------------------
import blue.io.*;
import blue.math.*;
// Application Class
// ---------------------------------------------------
class ColumnOfCubesApp
{
static public void main (String args[])
{
// Record given surface area and no. of cubes.
double surfaceArea = 587.785;
double numOfCubes = 5.0;
// Record number of cube faces exposed
// (by observation).
double numCubeFaces = 21.0;
// Calculate length of one side of cube.
double lengthOfSide = Math.sqrt(surfaceArea
/numCubeFaces);
// Calculate volume of structure,
// length x width x height.
double volColumnOfCubes = (numOfCubes
* lengthOfSide) * lengthOfSide
* lengthOfSide;
// Display result.
IO.println ("The volume of the column is "
+ volColumnOfCubes + " cubic feet.");
}
}
// Demo
// ---------------------------------------------------
/*
$ javac ColumnOfCubesApp.java
$ java ColumnOfCubesApp
The volume of the column is 740.4040924334622 cubic feet.
$
*/
|
|
|