01: package example;
02:
03: /** An example class to illustrate Jumble coverage. */
04: public class Mover {
05: /** How much slower to travel in the horizontal direction */
06: protected final int SLOWER = 5;
07:
08: protected int x, y;
09:
10: /** Move this object in one of the four possible directions.
11: * Horizontal movements have less effect than vertical ones.
12: *
13: * @throws RuntimeException if direction is not valid
14: * @param direction must be "left", "right", "up" or "down".
15: * @param speed how far/fast we would like it to move.
16: */
17: public void move(String direction, int speed) {
18: if (direction.equals("up")) {
19: y -= speed;
20: } else if (direction.equals("down")) {
21: y += speed;
22: } else if (direction.equals("left")) {
23: x -= speed / SLOWER;
24: } else if (direction.equals("right")) {
25: x += speed / SLOWER;
26: } else {
27: throw new RuntimeException("illegal direction: "
28: + direction);
29: }
30: }
31:
32: public String toString() {
33: return Integer.toString(x) + "," + Integer.toString(y);
34: }
35:
36: public String prettyString() {
37: return "(" + Integer.toString(x) + "," + Integer.toString(y)
38: + ")";
39: }
40: }
|