Question: Concepts inheritance Overview Background: Drawing programs are generally categorized as either image (bitmap) or object, meaning that the graphical information is represented as a mathematical
Concepts
- inheritance
Overview
Background: Drawing programs are generally categorized as either image (bitmap) or "object", meaning that the graphical information is represented as a mathematical description of the figures in the image, their sizes, colors, and so forth. You will implement supplier code for the latter, to support a program that allows the end user to put figures on the screen, select them, and manipulate them in various ways.
Specification
You will supply the classes to implement a square, a t-bar, a right triangle, and an ellipse.
We're going to take advantage of inheritance with using a super class: Shape.java Notice in Shape that there is only 1 dimension, height, and coordinates for one point. Most shapes can be define with just these 3 pieces of information. First, there's some work to do in the super class:
- Implement the isOn() method. Return true if the coordinates lie within the bounding box of Shape
- Implement moveCenterTo(), which moves the center of the Shape to those coordinates. Notice how the Shape class considers the (x,y) instance variables.
- Add JavaDoc comments
class Square, TBar, and RTriangle
Next, implement the subclasses Square, TBar, and RTriangle, Each of these shapes use the same value for width and height (their bounding box is square).
- Be smart with inheritance. Do not introduce new instance variables unless they are needed. Do not implement methods unnecessarily.
- You decide what point the instance variable coordinates represent. The center? The upper left corner of the bounding box? It's your choice (remember to document well).
- Override getName().
- Override isOn(). isOn() should be accurate for the specific shape, don't just rely on a point lying on the bounding box.
- For the t-bar, consider the shape as individual squares or rectangles and test if a point lies somewhere on them.
- For the right triangle, it will help if you come up with the equation for the hypotenuse. Remember that y coordinates increase as you go down in Java Graphics. The slope of the hypotenuse is 1, not -1.
- Does isOn() need to be overridden for the Square?
- Each subclass will need to implement the method to draw the figure on the provided Graphics space. If a figure is selected, draw the figure with the color and then an outline in black. If a figure is not selected, do not draw the black outline.
- For the t-bar shape, the height of the horizontal piece is 1/3 of the overall height. Same with the width of the vertical piece. Draw it using two rectangles.
- When a t-bar is selected, both rectangles should be drawn with the black outline.
Suggestions & Hints
As always, you will have success if you code and test in pieces. I recommend using the @Override notation to confirm that you are overriding methods and not overloading.
When it comes to drawing or implementing isOn, I encourage you to use some graph paper and draw shapes the coordinates for multiple points to help figure out the algorithm.
Documentation, Style
Please refer to the documentation and style guideline on the class website. All 4 classes should contain both algorithm and JavaDoc comments.
HEIGHTStep by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
