



|
|
CS1 Course Site
|
Programming Challenge Archive
General Problems Solving
Columns of Cubes
|
|
The Problem
: Column of Cubes. A structure is constructed by adjoining 5 cubes into a column and then removing the interior faces. The (external) surface area of the structure is 587.785 square feet. What is the volume of the structure?
JavaApplication --
Column Of Cubes
// General Information
// ---------------------------------------------------
// File: ColumnOfCubesApp.java
// Type: java application file
// Date: Mon Sep 18, 2000
// Name: James W. Bremenour
// Line: Calculates the volume of a column of 5 cubes
// Application Description
// ---------------------------------------------------
/*
Calculates the volume of a column of five cubes.
*/
// Required Packages
// ---------------------------------------------------
import blue.io.*;
import blue.math.*;
// Application Class
// ---------------------------------------------------
class ColumnOfCubesApp
{
static public void main (String args[])
{
// Set known values
double surfaceArea = 587.785;
int nrOfCubes = 5;
// Find the value of one side of one cube
double sideOfOneCube =
Math.sqrt((surfaceArea/((6*nrOfCubes)
- 2*(nrOfCubes-1))));
// Find the volume of the column
double volumeOfOneCube =
Math.pow(sideOfOneCube,3);
double volumeOfColumn =
nrOfCubes * volumeOfOneCube;
// Display the result
IO.print ("The volume of the column is: ");
IO.print (volumeOfColumn);
IO.print (" cubic feet");
IO.println ();
}
}
// Demo
// ---------------------------------------------------
/*
rocky - bremenou - cubes > java ColumnOfCubesApp
The volume of the column is: 690.5000771358459 cubic feet+
rocky - bremenou - cubes >
*/
|
|
|