Lab 4 Advanced OO and Inheritance

All work to be added, committed and pushed to the remote by 11:59PM on Sunday.
IMPORTANT: While you are in the lab, login in to a lab desktop, bring up chrome and visit this attendance app This will register your attendance in the lab. Make sure you have, at some point during the lab, logged in directly on a lab system (using the lab keyboard, monitor and mouse, no ssh!!).

Notes

Setup and Submission

Exercises

  1. Even and Odd

    Take a look at Even and EvenTest, understand this and duplicate it in Odd and OddTest.

  2. Complete PlayWithShapes.java

    Follow the instructions within the comments written in the file PlayWithShapes.java to complete this class.

  3. Extending a Class

    Take a look at the existing Rectangle and Circle classes. Create a Square class which extends Rectangle:

    • A Square is a Rectangle that has an (x, y) position, a color, and a width
    • This class should just have two constructors as follows:
      • By default (without any given arguments), a Square is created as blue, with width 10, and position (100, 100)
      • A Square can also be created with four arguments (String c, int width, int x, int y) that sets the color, width, and x,y values as the arguments given
      • Think about, whether it really makes sense to make Square a subclass of Rectangle. For some help in thinking about this, take a look at this discussion of the Liskov Substitution Principle, or The Liskov Substitution Principle

  4. Work through UnderstandingInheritance.java

    • Write comments in the file to describes all the methods that are called as a result of each line. For example...
    Square s=new Square(); // The line above calls the Square() constructor // which executes this("blue", 10, 100, 100); which calls // the Square(String c, int width, int x, int y) constructor // which executes super(c, width, width, x, y); which calls ... // ... (complete this)