Hello All !
I'm trying to write a Robot Class who have several methods.
One of its methods is move() that move the robot the direction his looking at, one step ahead.
I'm getting an error on this:
switch (Direction) {
If some one can help me find the mistake, and help me improved my code, I will be more than happy !!
My code:
import java.awt.*;
public class Robot {
private int roboId;
private Point location;
public static enum Direction {UP,DOWN,RIGHT,LEFT}
private Direction dir; // creates an object for the constructor
public static final int DX=1;
public static final int DY=1;
public static final int NO_MOVEMENT=0;
public Robot (int id, Point location, Direction dir){
this.roboId = id; // initialize roboID
if ((location.getX() <0)||(location.getY()<0)) // initialize Point location
this.location.setLocation(0,0); // in case (x,y) negative coordinate, set (0,0).
else
this.location.setLocation(location.getX(),location.getY());
this.dir = dir; // initialize Direction
}//Robot constructor
public int getId(){ //returns robot ID#
return roboId;
}
public Point getLocation(){ //returns robot (x,y) location
return location;
}
public Direction getDir(){ //returns robot direction
return dir;
}
public void move(){
switch (Direction) {
case Direction.RIGHT: location.translate(DX, NO_MOVEMENT); break;
case Direction.UP: location.translate(NO_MOVEMENT, -DY); break;
case Direction.LEFT: location.translate(-DX, NO_MOVEMENT); break;
case Direction.DOWN: location.translate(NO_MOVEMENT, DY); break;
default: System.out.println("Error in move(int)!");
}
}
}//class Robot