-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoordinate.java
More file actions
60 lines (46 loc) · 1.03 KB
/
Coordinate.java
File metadata and controls
60 lines (46 loc) · 1.03 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
//Class to accurately relay position of the piece.
public class Coordinate {
private int _row;
private int _col;
private String square;
private static final String COLUMNS = "ABCDEFGH";
public Coordinate( int row, int col ){
_row = row;
_col = col;
updateSquare();
}
public String toString(){
updateSquare();
return square;
}
public String updateSquare(){
square = COLUMNS.substring(_col-1, _col);
square += _row;
return square;
}
public int getRow(){
return _row;
}
public int getCol(){
return _col;
}
public int setRow( int x ){
_row = x;
updateSquare();
return _row;
}
public int setCol( int y ){
_col = y;
updateSquare();
return _col;
}
public static void main( String[] args ){
Coordinate bob = new Coordinate(1,5);
System.out.println(bob.getRow());
System.out.println(bob.getCol());
System.out.println(bob);
System.out.println(bob.setRow(5));
System.out.println(bob.setCol(1));
System.out.println(bob);
}
}