class Robot {
    String direction;
    int x, y;
    String name;
    Robot(String n, int x, int y, String dir) {
        name = n; this.x = x; this.y = y; direction = dir; 
    } 
    void moveForward() {
        System.out.println("Robot " + name + " now moves forward."); 
        if (direction.equals("North")) {
            y -= 1; 
        } else if (direction.equals("South")) {
            y += 1; 
        } else if (direction.equals("East")) {
            x += 1; 
        } else if (direction.equals("West")) {
            x -= 1; 
        } else {
            // nothing 
        }
    } 
    void turnLeft() {
        System.out.println("Robot " + name + " now turns left."); 
        if (direction.equals("North")) {
            direction = "West"; 
        } else if (direction.equals("South")) {
            direction = "East";          
        } else if (direction.equals("East")) {
            direction = "North";         
        } else if (direction.equals("West")) {
            direction = "South";         
        } else {
            // nothing 
        }
    }
    int getX() { return x; }
    int getY() { return y; }
    String direction() { return direction; } 
    void report() {
        System.out.println( "Robot " + name + " located at (" + x + 
                            ", " + y + ") facing " + direction ); 
    } 
}

So here's an example of using this class: 

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(); 
    } 
}

--