Return to Jeff's Main Page

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
My Intro to Object-Oriented Programming  
 
 
Programming Challenge Archive

Programming Assignment # 2
Far Corners Of A Room
 
A room measures 8 feet x 14 feet x 11 feet.   What is the distance from one corner to the furthest corner away from it?  

 
  JavaApplication - Programming Assignment # 2  -- Far Corners Of A Room

   // General Information
   // ---------------------------------------------------
  
   // File:  FarCornersApp.java
   // Type:  java application file
   // Date:  Mon Sep 25, 2000
   // Name:  Jeffrey R Norkoli
   // Line:  Find the distance between corners of a room.
  
   // Application Description
   // ---------------------------------------------------
  
   /*
       A room measures 8 feet x 14 feet x 11 feet.  
       What is the distance from one corner to the 
       furthest corner away from it? 
   */
  
   // Required Packages
   // ---------------------------------------------------
  
      import blue.io.*;
      import blue.shapes.*;
  
   // Application Class
   // ---------------------------------------------------
  
      class FarCornersApp
      {
         static public void main (String args[])
         {
     // Record room dimensions. 
     double length = 14.0; 
     double width = 11.0; 
     double height = 8.0; 
  
     // Use rectangles and diagonals to solve 
     // this problem. Determine diagonal across 
     // room floor. 
     Rectangle roomFloor = 
         new Rectangle(length,width); 
     double floorDiagonal = roomFloor.diagonal(); 
  
     // Having computed the diagonal across 
     // the floor, we can use the room's height 
     // (8'), to determine the diagonal from 
     // floor to ceiling along "floorDiagonal". 
     Rectangle floorToCeiling = new 
         Rectangle(floorDiagonal,height); 
     double farCornerDistance = 
         floorToCeiling.diagonal(); 
  
     // Display result. 
     IO.println ("The distance between the corners 
                  is " + farCornerDistance + " feet.");
         }
      }
  
   // Demo
   // ---------------------------------------------------
  
   /*
   $ javac FarCornersApp.java
   $ java FarCornersApp
   The distance between the corners is 
   19.519221295943137 feet.
   $ 
   */