York U: Redefine the Possible HOME | Current Students | Faculty & Staff | Research link: Future Students, Alumni & Visitors
Search »  
Department of Computer Science and Engineering
Home
Announcements
Course Calendar
Course Forum


Y graphic
CSE 1030 - Assignment #5 - Java Polymorphism - A Graphical User Interface

SC/CSE 1030 - Fall 2012 - Assignment #5

Java Polymorphism - A Graphical User Interface



The Object Oriented Programming feature "Polymorphism" is often used in constructing GUI (Graphical User Interface) programs. Your assignment for this week is to build a polymorphic set of graphics primitives for a GUI Drawing Program.

To complete this assignment you will need to create four classes, all four of which extend the DrawingObject abstract class (here is the API of the DrawingObject class). The APIs for the four classes you must implement are available here:

These four polymorphic classes are designed to be used by a drawing program to store the information about the shapes created by the user of the drawing program. The code for the drawing package has been provided for you here (Draw.java), all that it's missing are the implementations of the four DrawingObject subclasses. A screen print of the Draw application, showing the four graphics primitives, appears below:

Each of the four classes is responsible for maintaining the information for a single type of graphical object (an ellipse or oval, a line, a square, or an 'X'). The position and size of these objects are all defined by two cartesian coordinates - the upper left corner, and the lower right corner. For example, the DrawingLine object defines a straight line extending between the two points. The two points define the corners of the DrawingSquare and DrawingX objects. And the DrawingEllipse object defines the largest ellipse (or oval) that fits into the imaginary box defined by the two points.

The Draw program (and the "a5" tester program) communicate with the classes through the four abstract functions that are declared in the DrawingObject class. Some comments regarding these four functions are warranted:

void resizeObject(int x1, int y1, int x2, int y2)
This function is used by the Draw program to change the location and/or size of the object.

boolean wasClicked(int px, int py)
This function is used by the Draw program to determine whether the user has clicked on the object or not. The parameters (px,py) represent the cartesian point where the user has clicked the mouse. This function must search through all of the line segments that constitute this object, and return true if the point (px,py) hits any of those lines. (So, for example, the DrawingSquare object must check whether the click point landed on any of the four sides of the square.) Hint! there are two static utility functions defined in the DrawingObject class that you will find helpful.

Rectangle getBoundingBox()
This function returns a Rectangle object describing a "Bounding Box" for this object. A bounding box is the smallest (imaginary) rectange that completely contains (or surrounds) the object.

void drawObject(Graphics2D g2)
This function uses a "Graphics Context" object to draw the object. The graphics context, or Graphics2D object provides the functions necessary to draw the objects, in particular, see the drawLine() and drawOval() functions.

Note that although your code completes the provided Draw GUI program, a tester program (a5.java) has been provided to help you debug your code. A version of the tester program will be used for grading your assignment solutions, not the graphical Draw program, so make sure that your classes at least pass the tests in the tester program! You may wish to add additional tests of your own.

To complete this assignment, you must do these things:

  1. Implement the required four classes, matching the details in the four APIs: DrawingEllipse, DrawingLine, DrawingSquare, and, DrawingX.

    You are responsible for defining and managing the data members of these classes that you will need, and for implementing the functions described in the API.

  2. Include appropriate comments and Javadoc comments in your source code.

  3. You should test your implementation using the a5.java program.

  4. Submit your classes electronically before the deadline using the submit command:
    submit 1030 a5 DrawingEllipse.java DrawingLine.java DrawingSquare.java DrawingX.java

Some notes:

  1. The source code for the DrawingObject abstract superclass has been provided for you here: DrawingObject.java. The API for the DrawingObject class is available too.

    Note that you should not need to change the DrawingObject class to complete this assignment.

  2. You will find the following class useful for testing your code: a5.java. This program provides a simple command-line interface to several tests to help you test your code.

    You can also test your code by running the Draw program (the source code for the Draw program is provided here: Draw.java

  3. Your source code should be well organised and documented.

  4. Remember the Course's, Department's, and the University's policies on academic honesty - do your own assignment yourself. (Besides, doing it yourself is the only way to learn!)

  5. This assignment is due on Friday October 26, at noon. Late assignments will not be accepted.
    Start Early - Don't leave your assignment to the last minute!

  6. Remember that you can use the submit command more than once - if you submit your Symphony.java file again, it will replace the previous submission. So if you make a mistake, don't panic, just fix it, and resubmit it (before the deadline).

    Note that you do not need to submit all four classes at once, you can use the submit command to submit each Java file seperately, if that is more convenient for you.

    Additional information regarding the submit command can be found by typing man submit at the command line.

  7. Do not use the Type package, nor its earlier incarnation, the york package.

  8. Your programs must compile and run on the Prism computers.

  9. Your grade will be a number from 0 to 10 - one mark each for passing the tests in the a5.java program. The breakdown is:
    1 mark for creating the four subclasses that extend the DrawingObject class, to the point that we can create an instance of each class.
    1 mark for correctly implementing the .getBoundingBox() function for each of the four subclasses.
    1 mark for correctly implementing the .resizeObject() function for each of the four subclasses.
    1 mark for correctly implementing the DrawingEllipse.wasClicked() function for each of the four subclasses.
    1 mark for correctly implementing the DrawingLine.wasClicked() function for each of the four subclasses.
    1 mark for correctly implementing the DrawingSquare.wasClicked() function for each of the four subclasses.
    1 mark for correctly implementing the DrawingX.wasClicked() function for each of the four subclasses.
    1 mark for correctly implementing the .drawObject() function for each of the four subclasses.
    2 marks for coding style (nicely organised code with comments).

  10. Have FUN!






graphic rule