Overriding Methods

Note:  Please keep the programs that you create today, in case you have a dispute about your grades for the ICEs at the end of the quarter. When you're working with a partner, each person should save their own, individual copy

Part  1: Overriding: A Bit More Complicated Inheritance

 

            Download from the website and trace ICE_10_Demo_2.java.

 

Part  2: Overriding: Building a SafeRobot

           

            The basic Robot class that we've been using is very useful.  It's a Robot, and can do things like move, turn left, and pick things up.  This is all great, but one of the problems with this is that if you make a mistake, the you'll probably end up breaking the robot.  If your Robot moves into a Wall, the Robot will break.  If your Robot tries to pick up something in an empty intersection, the Robot will break.  If your Robot tries to put a thing down when it's got an empty backpack, the Robot will break.

            Your job in this ICE is to create a new type of Robot named SafeRobot.  You should override the move(), pickThing(), and putThing() methods, so that the robot won't break.  Even if the Robot is standing in front of, and facing a wall, your SafeRobot's move method should be smart enough to first ask "Is the path in front of me clear?"  Only if the answer is yes should the robot move forwards.

            Start with any file that you'd like; make sure that you test out your method (i.e., put a wall in front of the robot and try driving the robot into the wall, in order to check that move() is safe, etc)