



|
|
CS1 Course Site
|
Programming Challenge Archive
Shapes World Problem Solving
Far Corners of a Room
|
|
The Problem
: Far Corners of a Room. A room of dimensions 8 feet by 14 feet by 11 feet. What is the distance from one corner of the room to the far corner -- the one furthest from it?
JavaApplication --
Far Corners of a Room
// General Information
// ---------------------------------------------------
// File: FarCornersApp.java
// Type: java application file
// Date: Thu Sep 28, 2000
// Name: James W. Bremenour
// Line: Calculates the distance between two points
// Application Description
// ---------------------------------------------------
/*
Calculates the distance between the far corners of
a three dimensional room.
*/
// Required Packages
// ---------------------------------------------------
import blue.io.*;
import blue.shapes.*;
// Application Class
// ---------------------------------------------------
class FarCornersApp
{
static public void main (String args[])
{
// Set known values
int length = 8;
int width = 14;
int height = 11;
// Create aspects of the room
Rectangle front =
new Rectangle(length,height);
Rectangle floor =
new Rectangle(length,width);
// Create a helper shape to find the distance
Rectangle helper =
new Rectangle(floor.diagonal(),height);
// The diagonal of the helper Rectangle is the
// distance between the points
double distance = helper.diagonal();
// Display the result
IO.print("The distance between the");
IO.print(" corners is: ");
IO.print(distance + " feet");
IO.println();
}
}
// Demo
// ---------------------------------------------------
/*
$ java FarCornersApp
The distance between the corners is: 19.519221295943133 f+
eet
$
*/
|
|
|