Roger L. Kraft

CS 59000-03 - Programming Assignment 1

This assignment is a simple warm-up exercise that does not use object-oriented programming, just basic Java control structures and some logic. This assignment is due Thursday, August 29.

Download this zip file. In the zip file you will find a demonstration version of this assignment. (The demonstration version was written in C, that's why it is an exe file, not a class file.)

Write a Java program called PrintFrame.java that takes two integer parameters on its command line. Your program should print a "frame" in the console window consisting of two squares, one inside of the other, with the corners of the squares connected with 45 degree "lines". The dimensions of the two squares are given by the two integer parameters (the larger parameter is the outer dimension and the smaller parameter is the inner dimension). Here are a few examples. The command line parameters 20 and 12 should produce the following output in the console window. (Notice that these really are "squares" in that they have the same number of characters in their horizontal and vertical sides.)

********************
**                **
* *              * *
*  *            *  *
*   ************   *
*   *          *   *
*   *          *   *
*   *          *   *
*   *          *   *
*   *          *   *
*   *          *   *
*   *          *   *
*   *          *   *
*   *          *   *
*   *          *   *
*   ************   *
*  *            *  *
* *              * *
**                **
********************

The command line parameters 6 and 24 should produce the following output. Notice that the larger of the two input integers should be the dimension of the outer "square".

************************
**                    **
* *                  * *
*  *                *  *
*   *              *   *
*    *            *    *
*     *          *     *
*      *        *      *
*       *      *       *
*        ******        *
*        *    *        *
*        *    *        *
*        *    *        *
*        *    *        *
*        ******        *
*       *      *       *
*      *        *      *
*     *          *     *
*    *            *    *
*   *              *   *
*  *                *  *
* *                  * *
**                    **
************************
The command line parameters 21 and 3 should produce the following output. (The parameters 21 and 4 should produce the same output, see the next paragraph below.)
*********************
**                 **
* *               * *
*  *             *  *
*   *           *   *
*    *         *    *
*     *       *     *
*      *     *      *
*       *   *       *
*        ***        *
*        * *        *
*        ***        *
*       *   *       *
*      *     *      *
*     *       *     *
*    *         *    *
*   *           *   *
*  *             *  *
* *               * *
**                 **
*********************

If the difference between the two parameters is not an even integer, your program should decrease the smaller parameter by 1 and use that new value. If the two parameters are equal, you should draw only the outer frame. If either parameter is negative, your program should return an error message and quit.

Turn in a zip file called CS507Hw1Surname.zip (where Surname is your last name) containing your source code file PrintFrame.java.

This assignment is due Thursday, August 29.