Homework 1 - Inheritance and polymorphism

Reading: Java by Dissection, Chapter 7.

Due Monday January 14th, at 10pm.

Program Description - A Simple Drawing Package

For this assignment you are to implement a collection of classes that support a very simplified graphics system. Your system will be capable of drawing various shapes (rectangles, lines, and polygons). The shapes will be drawn on a particular "device" within a "frame". To test your classes, you will read specifications for the various shapes from System.in (e.g. using a java.util.Scanner) and then create the appropriate frame or frames.

The classes you create must include:

The following are provided as part of this exercise. These classes are NOT TO BE MODIFIED in any way for this assignment.

Your classes (especially Frame) must provide the methods shown in the example Main below. Your classes must work with the sample Main below.

Input

Input will be a series of commands taken from the following list. The shapes are all given an integer id, to allow the shape to be modified or deleted. All input values will be white space delimited. The main program is intended to be an interactive test program for your other classes, so some type of simple prompt would be appropriate. In addition your program must support a command line arugment of -q for quiet mode. In quite mode, no prompt is printed. This is intended to be used for testing where input comes from a file (via file redirection) and output also goes to a file (via file redirection). Be sure and test your program using file redirection. A common mistake is to create multiple Scanner objects which will fail when using file redirection.

Output

Output is a series of frame displays, possibly with some intermixed error messages. There should be one frame display for each D and S command in the input.

Sample Input

F 1111 60 25
R 100 2 2 50 20
P 300 3 1 1 30 10 15 20
D
F 2222 70 40
R 100 3 2 50 20
L 200 12 2 50 20
D
S 1111
X 100
D
Q

Sample Output

The following shows the input and output mixed as would be the case in interactive mode. If input was from a file using file redirection, the input commands would of course not be shown in the output.
os-prompt: java GraphicsTest
enter command>F 1111 60 25
enter command>R 100 2 2 50 20
enter command>P 300 3 1 1 30 10 15 20
enter command>D
**************************************************************
*                                                            *
* **                                                         *
*  ***************************************************       *
*  *   ****                                          *       *
*  **      ***                                       *       *
*  * *        ***                                    *       *
*  *  *          ***                                 *       *
*  *  *             ***                              *       *
*  *   *               ****                          *       *
*  *    *                  ***                       *       *
*  *     *                    **                     *       *
*  *     *                   **                      *       *
*  *      *                 *                        *       *
*  *       *              **                         *       *
*  *        *            *                           *       *
*  *        *          **                            *       *
*  *         *        *                              *       *
*  *          *     **                               *       *
*  *           *   *                                 *       *
*  *           * **                                  *       *
*  *            *                                    *       *
*  *                                                 *       *
*  ***************************************************       *
*                                                            *
*                                                            *
**************************************************************
enter command>F 2222 70 40
enter command>R 100 3 2 50 20
enter command>L 200 12 2 50 20
enter command>D
************************************************************************
*                                                                      *
*                                                                      *
*   ***************************************************                *
*   *          **                                     *                *
*   *            **                                   *                *
*   *              **                                 *                *
*   *                **                               *                *
*   *                  **                             *                *
*   *                    **                           *                *
*   *                      **                         *                *
*   *                        **                       *                *
*   *                          ***                    *                *
*   *                             **                  *                *
*   *                               **                *                *
*   *                                 **              *                *
*   *                                   **            *                *
*   *                                     **          *                *
*   *                                       **        *                *
*   *                                         **      *                *
*   *                                           **    *                *
*   *                                             **  *                *
*   *                                                 *                *
*   ***************************************************                *
*                                                                      *
*                                                                      *
*                                                                      *
*                                                                      *
*                                                                      *
*                                                                      *
*                                                                      *
*                                                                      *
*                                                                      *
*                                                                      *
*                                                                      *
*                                                                      *
*                                                                      *
*                                                                      *
*                                                                      *
*                                                                      *
*                                                                      *
************************************************************************
enter command>S 1111
**************************************************************
*                                                            *
* **                                                         *
*  ***************************************************       *
*  *   ****                                          *       *
*  **      ***                                       *       *
*  * *        ***                                    *       *
*  *  *          ***                                 *       *
*  *  *             ***                              *       *
*  *   *               ****                          *       *
*  *    *                  ***                       *       *
*  *     *                    **                     *       *
*  *     *                   **                      *       *
*  *      *                 *                        *       *
*  *       *              **                         *       *
*  *        *            *                           *       *
*  *        *          **                            *       *
*  *         *        *                              *       *
*  *          *     **                               *       *
*  *           *   *                                 *       *
*  *           * **                                  *       *
*  *            *                                    *       *
*  *                                                 *       *
*  ***************************************************       *
*                                                            *
*                                                            *
**************************************************************
enter command>X 100
enter command>D
**************************************************************
*                                                            *
* **                                                         *
*  ****                                                      *
*  *   ****                                                  *
*   *      ***                                               *
*    *        ***                                            *
*     *          ***                                         *
*     *             ***                                      *
*      *               ****                                  *
*       *                  ***                               *
*        *                    **                             *
*        *                   **                              *
*         *                 *                                *
*          *              **                                 *
*           *            *                                   *
*           *          **                                    *
*            *        *                                      *
*             *     **                                       *
*              *   *                                         *
*              * **                                          *
*               *                                            *
*                                                            *
*                                                            *
*                                                            *
*                                                            *
**************************************************************
enter command>Q

Sample Input2

The commands do not need to be one per line.
F 1111 60 25 R 100 2 2 50 20 P 300 3 1 1 30 10 15 20 D
F 2222 70 40 R 100 3 2 50 20 L 200 12 2 50 20 D S 1111 X 100 D
Q

Sample Ouput2

The output is the same as for the first input except that the intermixing of commands between frames would be different, or with the -q flag and file redirection there would be no command output, just the frames.

Getting Started

I strongly recommend that you first create the Frame, Line, and Rectangle classes that are required for the test program, Main.java, to work. This demonstrates most of the key inheritance ideas in this assignment. When that is working, then create your GraphicsTest program. It is important to not mix up your "application" (GraphicsTest) which requires integer ids to be associated with frames and shapes, and your "graphics package" which knows nothing about ids.

You can recieve 70% on this assignment if you complete the Frame, Rectangle, Line, and Polygon classes.

For the GraphicsTest portion for of the assignment, I'm providing one additional file, FrameMap.java that I used to simply the association of shape ids with frames. Please note that two different frames can contain different shapes with the same id which is why I create a separate table (I used a HashMap) of shapes ids for each frame. You are welcome to use this class but it is not required.


Design Points

25 points - properly structure your files Frame, Line, Polygon, and Rectangle using ConsoleGraphics and TGraphics as appropriate.

Correctness Points

20 points - your files work correctly with the test Main.java.

3 points for each of the commands (F, R, L, P, D, S, C, X)

3 points quite mode

3 points miscellaneous

This page maintained by Charlie McDowell. Email regarding this site.