Create the classes RightTriangle and Rectangle, each of which is derived from the abstract class ShapeBase in Listing 8.19. Then derive a class Square
from the class Rectangle. Each of these three derived classes will have two additional methods to calculate area and circumference, as well as the inherited methods. Do not forget to override the method drawHere. Give your classes a reasonable complement of constructors and accessor methods. The Square class should include only one dimension, the side, and should automatically set the height and width to the length of the side. You can use dimensions in terms of the character width and line spacing even though they are undoubtedly unequal, so a square will not look square (just as a Rectangle object, as discussed in this chapter, won’t look square.) Write a driver program that tests all your methods.
This project is most easily written by modifying the programs in the text. Base RightTriangle.java on Triangle.java (Listing 8.14), Rectangle.java on Rectangle.java (Listing 8.13), and MoreGraphicsDemo.java on TreeDemo.java (Listing 8.15). Square.java is derived from Rectangle, so it is just a matter of using the parent’s methods with both height and width set to the length of the side of the square. Note that special attention is required to draw the correct figures when the base, width, or height values are either 0 or 1.
See the code in RightTriangle.java, Rectangle.java, SquarePr7,java, and MoreGraphicsDemo.java.
You might also like to view...
Describe how fan and chasm traps can occur in an ER model and how they can be resolved.
What will be an ideal response?
If you are creating a Web site for a client, ask your client to see if there are any specific graphics (pre-existing images or clip art) that they want on the site. Often an organization will have an identifying logo that will need to appear, particularly on the home page.
What will be an ideal response?
________ force you to practice safe computing and thus prevent a lot of potential problems from affecting a system
A) Keychains B) AUPs C) EFSs D) BitLockers
Pictures can be made to look like sketches or paintings by applying:
A) alignment effects. B) leveling effects. C) artistic effects. D) paging elements.