-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSonda.java
More file actions
63 lines (53 loc) · 1.29 KB
/
Copy pathSonda.java
File metadata and controls
63 lines (53 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
public class Sonda {
private int row;
private int col;
private char dir;
public Sonda(int x, int y, char dir) {
this.row = x;
this.col = y;
this.dir = dir;
}
public int getRow() {
return row;
}
public int getCol() {
return col;
}
public char getDirection() {
return dir;
}
public void setRow(int x) {
this.row = x;
}
public void setCol(int y) {
this.col = y;
}
public void setDirection(char d) {
this.dir = d;
}
public char newDirection(char d) {
char c = this.dir;
if (d == 'L') {
if (this.dir == 'N') c = 'W';
if (this.dir == 'W') c = 'S';
if (this.dir == 'S') c = 'E';
if (this.dir == 'E') c = 'N';
}
else {
if (this.dir == 'N') c = 'E';
if (this.dir == 'W') c = 'N';
if (this.dir == 'S') c = 'W';
if (this.dir == 'E') c = 'S';
}
return c;
}
public int[] nextPosition() {
int x = this.row;
int y = this.col;
if (dir == 'N') y = y + 1;
if (dir == 'W') x = x - 1;
if (dir == 'S') y = y - 1;
if (dir == 'E') x = x + 1;
return new int[]{x, y};
}
}