Question: Consider the following skeleton for a Robot class, which has private fields for storing the location of a Robot object, its name, and the direction


Consider the following skeleton for a Robot class, which has private fields for storing the location of a Robot object, its name, and the direction it's facing (North for a direction parallel to the positive y axis, South for the negative y axis, East for the positive x axis, or West for the negative x axis). It also has stub methods for constructing a Robot object, changing the direction, and moving the location of the robot in the direction it's facing. public class Robot { private String name; private char direction; //'N','S','E', or 'W' private int xLoc, yLoc; // the (x, y) location of the robot // Initialize name, direction, and (x, y) location public Robot(String name, char dir, int x, int y) { ... } public String toString() { return name + " is standing at (" +x+","+y+") and facing" + direction); } // turn 90 degrees clockwise, e.g. 'N' changes to 'E','E' to 'S', ... public void turnClockwise() { ... } // turn 90 degrees counterclockwise, e.g. 'N' to 'W', 'W' to 'S', ... public void turn CounterClockwise() {... } // move numSteps in direction you are facing, // e.g. if 'N' 3 steps, then y increases 3 public void takeSteps(intnumSteps) { ... } } Sample main function: public static void main(String args[]) { Robot robby = new Robot("Robby", 'N', 10, 12); for (inti = 0; i
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
