weight = 14
Lab 4: Inheritence with Shapes
- Translate UML class diagrams into source code
- Construct software which using an abstract class and polymorphism
- Employ aggregation and composition in the development of software
- Use javadoc to determine appropriate use of an unfamiliar class
Your assignment is to write the
The classes are part of an inheritance hierarchy that is shown in the UML
class diagram below. Note that the
Shape class is an abstract class.
Also, be sure that your implementation adheres to the visibility modifiers
shown in the diagram.
Place each of these classes in a package that uses your MSOE username as the name.
Implementation specific details for these classes is found in the javadoc.
The FaceMaker class has already been partially implemented.
Once you have implemented the
Rectangle classes, you should be
able to run the
FaceMaker program and see a face made of rectangles displayed.
The program makes use of the classes that you must implement to create the following:
You will need to refactor the
FaceMaker class and add additional functionality
as described below.
When completed, your program should ask the user for the desired type of shapes to use when generating the face. The user should be able to select any of the following options:
- Rectangle — draws face using rectangles as shown above
- Circle — draws face using circles for each facial component
- Triangle — draws face using triangles for each facial component
- Labeled Rectangle — draws face using labeled rectangles for each facial component
- Labeled Triangle — draws face using labeled triangles for each facial component
- Random — draws face using one of the previous shapes for each facial component
If the user enters something other than the one of the above options, then the program should draw a face using a randomly selected shape type for each facial component. For example, the program may draw a rectangle for the head, a labeled rectangle for the right eye, a triangle for the left eye, and circles for the nose and mouth.
The program relies on the WinPlotterFX class. Prof. Jones
WinPlotterFX class, and the documentation for the class is
found here. You will need to download and then add the
WinPlotterFX.jar file to your build path (see instructions below).
Accessing the .jar File
For this assignment, you will need to make use of the WinPlotterFX.jar.
In order to be able to access the
WinPlotterFX class in the
- Create a libs folder in your IntelliJ project folder
- Download the WinPlotterFX.jar file and save it in the newly created libs folder.
- Select File -> Project Structure
- Select Modules from the Project Settings on the left
- Select the Dependencies tab on the right
- Select the + on the far right
- Select Libraries -> Java from the drop-down menu
- Select the libs folder you created above and click OK
- In the Configure Library dialog box that appears, accept the default settings: Name = libs and Level = Project Library
- Click OK to close the Project Structure window
You should now have access to the
in your project code.
- Every class in this inheritance hierarchy, except the
Shapeclass implements the
drawmethods all take a single argument, which is a reference to the
WinPlotterFXobject created at the beginning of the
mainmethod in the
FaceMakerclass. As a result, all shapes use the same
WinPlotterFXobject for drawing.
- Each implementation of the
drawmethod must use methods from the
WinPlotterFXclass to draw the desired shape.
- To help you understand what you must write for each class (and how to draw each shape), read the Javadoc for the Shape-derived classes.
Just For Fun
Once you have met the requirements of the assignment, you may enjoy doing one or more of the following:
- Create a completely separate program that draws a picture of your own choosing.
- Implement the
Pointclass shown in the UML class diagram and add freckles to the face. As an extra challenge, try to keep the freckles only on the skin.
- Use different colors for the shapes.
- Draw ears and/or hair.
- Use multiple shapes to represent facial components (e.g., add a pupil in the each eye).
This laboratory assignment was developed Dr. Chris Taylor, and Prof. Sean Jones.