Java Reference
In-Depth Information
Additional programming exercises are available in WileyPLUS.
PROGRAMMING PROJECTS
Project 10.1. Your task is to program robots with varying behaviors. The
robots try to escape a maze, such as the following:
A robot has a position and a method
void move (Maze m)
that
modifies the position. Provide a common superclass
Robot
whose
move
method does nothing. Provide subclasses
RandomRobot
,
RightHandRuleRobot
, and
MemoryRobot
. Each of these robots
has a different strategy for escaping. The
RandomRobot
simply makes
random moves. The
RightHandRuleRobot
moves around the maze
so that it's right hand always touches a wall. The
MemoryRobot
remembers all positions that it has previously occupied and never goes
back to a position that it knows to be a dead end.
Project 10.2. Implement the
toString
,
equals
, and
clone
methods
for all subclasses of the
BankAccount
class, as well as the
Bank
class
of
Chapter 7
. Write unit tests that verify that your methods work
correctly. Be sure to test a
Bank
that holds objects from a mixture of
account classes.
495
496
ANSWERS TO SELF-CHECK QUESTIONS
1. Two instance fields:
balance
and
interestRate
.
2.
deposit
,
withdraw
,
getBalance
, and
addInterest
.
3.
Manager
is the subclass;
Employee
is the superclass.
4. To express the common behavior of text fields and text components.