Homework Assignment Two: A Simple Robot

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:

all at the same time. The Robot needs to be able to: The Robot also needs to remember its location.

Two methods:

can be used to report the current values of the robot's location.

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:

The robot also needs to be able to: Here's a sample program with two robots:
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(); 
    } 
}
This would produce the following output:
frilled.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%
Your task is to write Robot.java that describes the robots.


Last updated: Jun 25, 2001 by Adrian German for A201