



|
|
CS1 Course Site
|
Programming Challenge Archive
Shapes World
Alien Chessman
|
|
|
JavaApplication --
AlienChessman
// General Information
// ---------------------------------------------------
// File: AlienChessmanApp.java
// Type: java application file
// Date: Fri Sep 29, 2000
// Name: Kara Becker
// Line: Determine the length of the journey.
// Application Description
// ---------------------------------------------------
/*
Compute the length of the alien chessman's journey over +
a chessboard in inches usine the given information.
*/
// Required Packages
// ---------------------------------------------------
import blue.io.*;
import blue.shapes.*;
// Application Class
// ---------------------------------------------------
class AlienChessmanApp
{
static public void main (String args[])
{
//Create chessboard.
double chessboardSide = 19.6;
Square chessboard = new Square(chessboardSide);
double blockLength = chessboardSide / 8;
double blockWidth = chessboardSide / 8;
Square block = new Square(blockLength);
//Create the five rectangles using imaginative constructu+
re.
Rectangle helperOne = new Rectangle(blockLength,blockWidt+
h*4);
double helperOneDiag = helperOne.diagonal();
Rectangle helperTwo = new Rectangle(blockLength*4,blockWi+
dth*3);
double helperTwoDiag = helperTwo.diagonal();
Rectangle helperThree = new Rectangle(blockLength*2,block+
Width);
double helperThreeDiag = helperThree.diagonal();
Rectangle helperFour = new Rectangle(blockLength,blockWid+
th*5);
double helperFourDiag = helperFour.diagonal();
Rectangle helperFive = new Rectangle(blockLength*6,blockW+
idth*3);
double helperFiveDiag = helperFive.diagonal();
//Compute the total length of the journey.
double totalLength = helperOneDiag + helperTwoDiag + help+
erThreeDiag + helperFourDiag + helperFiveDiag;
//Display the results.
IO.println("The distance travelled is " + totalLength + "+
inches.");
}
}
// Demo
// ---------------------------------------------------
/*
$ javac AlienChessmanApp.java
$ java AlienChessmanApp
The distance travelled is 56.75767277056354 inches.
$
*/
|
|
|