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
- During the lab, if you know what you are doing, and can help your neighbour, then help them. If you need help, ask us or your neighbour.
Setup and Submission
- Login to a lab system; cd to your local copy of your repo OR clone
it again (see lab01);
git pullto get an up-to-date copy of the repo. The folderlab04should be there. - Launch IntelliJ (if you see a blank screen, close the blank tab). You can start IntelliJ (in the lab) from the command line via
/opt/idea-IC-252.23892.409/bin/idea - File > Open Project or Folder
- Click on "Directory..." and select the lab04 folder; then click on "Finish".
- The lab04 project should now show up in your sidebar. Work with the files in the project
- As you work on the lab, add, commit, and push your changes like how you did it in Lab 1. You should use the terminal for the Git commands rather than using the git features built in IntelliJ because we want you to learn to be able to use Git even when not using IntelliJ!
Exercises
- Even and Odd
Take a look at Even and EvenTest, understand this and duplicate it in Odd and OddTest.
- Complete
PlayWithShapes.javaFollow the instructions within the comments written in the file
PlayWithShapes.javato complete this class. - 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
- 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)