PHW6: Rectangle

In class we saw how to use inheritance to reuse code between our Ellipse and Circle classes. Now it’s your turn.

Rx: <10 min Av: 10-20 min Sd: 20-30 min DNF: 30+ min

Instructions

  1. If you haven’t been following along in class, download the Shapes Project and import it into your workspace.
  2. Use inheritance to add a Rectangle class to your Shapes project. First, think about how Square and Rectangle are related. Should Rectangle extend Square, or vice versa? We went over both ways in class.
  3. Determine what fields are needed in the Square & Rectangle classes. Overlapping fields should only be in one class.
  4. Your Rectangle & Square classes should have at least 3 constructors each:
    • Default constructor (no parameters)
    • Constructor with parameters for each field except outlineColor
    • Constructor with parameters for each field
  5. Add get & set methods for all the fields. There should not be any duplicated get/set methods.
  6. Make sure the getArea() and getPerimeter() methods work for both classes, and test in main by creating at least one Rectangle and one Square object.
  7. Make sure the draw() method works for both classes and test it by adding a Rectangle and Square to your Picture class.
  8. Run the program to verify your changes.