Homework 3 - Inheritance and polymorphism


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

Reading: Chapter 7.

Due At 10pm, February 10, 2005. Late work will be accepted for 48 hours past the due date, with a one point penalty for each hour late.

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(), or 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 Rectangle, Line, Polygon, and Frame classes must also work with the SampleGraphicsTest which is available in /afs/cats/courses/cmps109-cm/java. This implies the following:

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. For the commands r, l, and p, if there is already a shape with the specified id in the current frame, delete the old shape and replace it with the new shape and print a warning message that the shape was 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
**************************************************************
*                                                            *
* **                                                         *
*  ****                                                      *
*  *   ****                                                  *
*   *      ***                                               *
*    *        ***                                            *
*     *          ***                                         *
*     *             ***                                      *
*      *               ****                                  *
*       *                  ***                               *
*        *                    **                             *
*        *                   **                              *
*         *                 *                                *
*          *              **                                 *
*           *            *                                   *
*           *          **                                    *
*            *        *                                      *
*             *     **                                       *
*              *   *                                         *
*              * **                                          *
*               *                                            *
*                                                            *
*                                                            *
*                                                            *
*                                                            *
**************************************************************
enter command>

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
If the above was used via file redirection and quiet mode, the output would be as shown below.
**************************************************************
*                                                            *
* **                                                         *
*  ****------|                                               *
*  *|******  |                                               *
*   *  *** ***                                               *
*   |*    ***|***                                            *
*   | *      **  ***                                         *
*   | *      | ***  ***                                      *
*   |  *     |    ***  ****                                  *
*   |   *    |       **    ***                               *
*   |    *   |         ***    **                             *
*   |    *   |            *****                              *
*   |     *  |              ***                              *
*   |      * |            **   ***                           *
*   |       *|           *        ***                        *
*   |       *|         **            **                      *
*   |        *        *                ***                   *
*   |        |*     **                    ***                *
*   |        | *   *                         **              *
*   |        | * **                            ***           *
*   |        |  *                                 **         *
*   |--------|                                               *
*                                                            *
*                                                            *
*                                                            *
**************************************************************
************************************************************************
*                                                                      *
*                                                                      *
*   |--------**--------------------------------------|                 *
*   |          **                                    |                 *
*   |            **                                  |                 *
*   |              **                                |                 *
*   |                **                              |                 *
*   |                  **                            |                 *
*   |                    **                          |                 *
*   |                      **                        |                 *
*   |                        **                      |                 *
*   |                          ***                   |                 *
*   |                             **                 |                 *
*   |                               **               |                 *
*   |                                 **             |                 *
*   |                                   **           |                 *
*   |                                     **         |                 *
*   |                                       **       |                 *
*   |                                         **     |                 *
*   |                                           **   |                 *
*   |                                             ** |                 *
*   |------------------------------------------------|                 *
*                                                                      *
*                                                                      *
*                                                                      *
*                                                                      *
*                                                                      *
*                                                                      *
*                                                                      *
*                                                                      *
*                                                                      *
*                                                                      *
*                                                                      *
*                                                                      *
*                                                                      *
*                                                                      *
*                                                                      *
*                                                                      *
*                                                                      *
*                                                                      *
************************************************************************
**************************************************************
*                                                            *
* **                                                         *
*  ****------|                                               *
*  *|******  |                                               *
*   *  *** ***                                               *
*   |*    ***|***                                            *
*   | *      **  ***                                         *
*   | *      | ***  ***                                      *
*   |  *     |    ***  ****                                  *
*   |   *    |       **    ***                               *
*   |    *   |         ***    **                             *
*   |    *   |            *****                              *
*   |     *  |              ***                              *
*   |      * |            **   ***                           *
*   |       *|           *        ***                        *
*   |       *|         **            **                      *
*   |        *        *                ***                   *
*   |        |*     **                    ***                *
*   |        | *   *                         **              *
*   |        | * **                            ***           *
*   |        |  *                                 **         *
*   |--------|                                               *
*                                                            *
*                                                            *
*                                                            *
**************************************************************
**************************************************************
*                                                            *
* **                                                         *
*  ****                                                      *
*  * ******                                                  *
*   *  *** ***                                               *
*    *    *** ***                                            *
*     *      **  ***                                         *
*     *        ***  ***                                      *
*      *          ***  ****                                  *
*       *            **    ***                               *
*        *             ***    **                             *
*        *                *****                              *
*         *                 ***                              *
*          *              **   ***                           *
*           *            *        ***                        *
*           *          **            **                      *
*            *        *                ***                   *
*             *     **                    ***                *
*              *   *                         **              *
*              * **                            ***           *
*               *                                 **         *
*                                                            *
*                                                            *
*                                                            *
*                                                            *
**************************************************************

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

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