Finch Inheritance Practice Assignments

Overview

You may not have know this, but when you have used a Finch class before, it is already inheritance from a Robot class. In these practice assignments, we're going to add another layer to that inheritance hierarchy.

Resources

See the Finch Methods Practice Assignments for instructions for setting up and running the Finch robots.

Practice Assignments

FinchDog

Create a FinchDog child class that inherits from the Finch class. Add two methods to your FinchDog class:

bark

Add in a bark method that makes multiple sounds when called.

wag

Add in a wag method that takes an int for the number of times to "wag" its tail. Simulate wagging a tail by lighting up the LEDs on the robot.

Write driver code that creates a FinchDog object, calls bark and wag at least once each. Additionally, call at least one method from the Finch class (like setMove).

FinchSloth

Inheritance allows us to leverage an existing class and to change the behavior of certain actions. For this assignment, create a FinchSloth class that inherits from the Finch class. Change the behavior of each of the movement methods (setMove, setTurn and setMotors) so that the speed is 1/10th of the requested speed. For example, if setMove("F", 10.0, 50.0) was called on a FinchSloth object, it would up calling setMove("F", 10.0, 5.0). Be sure to use the appropriate annotation before each of those methods.

Write driver code that calls each of the movement methods.

FinchStepCounter

Create a FinchStepCounter class that inherits from the Finch class. Add in an int instance variable to your FinchStepCounter class. Also, write a constructor that initializes that variable. Each time setMove is called on a FinchStepCounter object, increment that number of steps taken.

Write driver code to instantiate a FinchStepCounter object. Make multiple calls of the setMove method on that object and display the total number of steps.

OPTIONAL challenges:

  1. Display the number of steps on the LED array
  2. Also increment the number of steps when the setTurn and setMotors methods are called.

Final Reflection

Notice how little code was needed to create a new class that can do everything that the Finch class can do and more.