![]() |
![]() Second Summer 2002 |
You have to define a class Robot
that describes
a robot very similar to the one you worked with in the first
lab. To clarify how easy this problem is we need to say that
metaphorically your robot is:
Penguin
Tigger
BankAccount
Rectangle
ConsoleReader
String
Robot
needs to be able to:
turnLeft
(90 degrees)
moveForward
(one step)
Robot
also needs to remember its location. Two methods:
getX()
, and
getY()
The location of the robot is a pair ( x , y ) of integers, that describes the position of the robot.
When you create a Robot
one need specify:
direction()
it's facing (N, S, W, E)
report()
(x, y, name, direction)
This would produce the following output:class Walk { public static void main(String[] args) { Robot a = new Robot("Alice", 2, 3, "North"); a.report(); Robot q = new Robot("Queen", -4, -1, "West"); q.report(); a.turnLeft(); a.report(); a.moveForward(); a.report(); a.turnLeft(); a.report(); a.moveForward(); a.report(); a.moveForward(); a.report(); a.moveForward(); a.report(); q.moveForward(); q.report(); q.turnLeft(); q.report(); } }
Your task is to writefrilled.cs.indiana.edu%java Walk Robot Alice located at (2, 3) facing North Robot Queen located at (-4, -1) facing West Robot Alice now turns left. Robot Alice located at (2, 3) facing West Robot Alice now moves forward. Robot Alice located at (1, 3) facing West Robot Alice now turns left. Robot Alice located at (1, 3) facing South Robot Alice now moves forward. Robot Alice located at (1, 4) facing South Robot Alice now moves forward. Robot Alice located at (1, 5) facing South Robot Alice now moves forward. Robot Alice located at (1, 6) facing South Robot Queen now moves forward. Robot Queen located at (-5, -1) facing West Robot Queen now turns left. Robot Queen located at (-5, -1) facing South frilled.cs.indiana.edu%
Robot.java
that describes the robots.
Please
take a moment to think about the referential we use in this problem which
is the same one that we use in computer graphics (see lecture notes three on
Jun 19)
which is also the reason for which Tigger is (let's say) upside down on the
main page of this web site. As always, please let us know if you have any
questions, of course.
Grading scale.
Robot
being
able to store the location, name, and direction facing
(x, y)
,
the direction, and the name individually
report()
, and
Robot
's ability to
turnLeft()
and moveForward()
as shown
That's a total of 95 (which is the highest A). For more come up with something worth it.
Let us know if you have any questions or if you need any help.