CS 123 - Programming Assignment 7

In this assignment you will write a (static) method that draws a "picture frame" like drawing in the console window. This assignment uses lots of loops and conditional statements. This assignment is due Wednesday, November 4.

Write a class file called PictureFrame.java that contains a static method printFrame(int i, int j) that takes two (even) integer parameters. This method 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. Here are a couple of examples. The method call PictureFrame.printFrame(20, 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 method call PictureFrame.printFrame(6, 24) should produce the following output. Notice that the larger of the two input integers should be the dimension of the outer "square".
************************
**                    **
* *                  * *
*  *                *  *
*   *              *   *
*    *            *    *
*     *          *     *
*      *        *      *
*       *      *       *
*        ******        *
*        *    *        *
*        *    *        *
*        *    *        *
*        *    *        *
*        ******        *
*       *      *       *
*      *        *      *
*     *          *     *
*    *            *    *
*   *              *   *
*  *                *  *
* *                  * *
**                    **
************************

Be sure that your method works with the "boundary cases". For example, what should the following method calls produce?

   PictureFrame.printFrame(12, 12);
   PictureFrame.printFrame(12, 10);
   PictureFrame.printFrame(12, 2)
   PictureFrame.printFrame(12, 0)

Also write a main() method for PictureFrame class that prompts the user for the two even integer dimensions. If one of the input integers is not even, ask the user for another integer. The main() method should then call the printFrame() method with the user's parameters. The main() method should continue to prompt the user for input and draw "frames" until the user inputs 0 as one of the dimensions.

Turn in a zip file called CS123Hw7Surname.zip containing your PictureFrame.java file. This assignment is due Wednesday, November 4.


Return to the main homework page.
Return to the CS 123 home page.


compliments and criticisms