Homework 3 - Inheritance and polymorphism


[Homepage] | [General Lab Info] | [TA's & Tutors] | [FAQ's] | [Homework] | [Excellent Programs] | [Exams]

Reading: Chapter 7.

Due At 8:00am, February 4, 2002, submit is turned off automatically. Work turned in after that time will not be accepted for grading.

Program Description - A Simple Drawing Package

For this assignment your 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 Console.in.readXXX()), 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.

NEW ADDITION: 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 inputs 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).

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

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.
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
**************************************************************
*                                                            *
* **                                                         *
*  ****                                                      *
*  *   ****                                                  *
*   *      ***                                               *
*    *        ***                                            *
*     *          ***                                         *
*     *             ***                                      *
*      *               ****                                  *
*       *                  ***                               *
*        *                    **                             *
*        *                   **                              *
*         *                 *                                *
*          *              **                                 *
*           *            *                                   *
*           *          **                                    *
*            *        *                                      *
*             *     **                                       *
*              *   *                                         *
*              * **                                          *
*               *                                            *
*                                                            *
*                                                            *
*                                                            *
*                                                            *
**************************************************************

Sample Input2

The commands do not need to be one per line.
F 1111 60 25 R 100 3 2 10 20 L 200 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

Sample Ouput2

The output is the same as for the first input except that the intermixing of commands between frames would be different.
[Homepage] | [General Lab Info] | [TA's & Tutors] | [FAQ's] | [Homework] | [Excellent Programs] | [Exams]

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