-
Notifications
You must be signed in to change notification settings - Fork 0
/
Coordinates.java
101 lines (65 loc) · 1.75 KB
/
Coordinates.java
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/**
* Stack data structure
*
* @Coordinates Class
* @Author - Danny Guan
* @Version - 1
*
*/
import java.util.ArrayList;
public class Coordinates {
ArrayList<Integer> Coordinates = new ArrayList<>();
// Empty Constructor
public Coordinates(){}
/**
* Adds a new value into the stack
* @adds a new value, pushes other values 1 index ahead
*/
public void push(int toAdd){
Coordinates.add(0, toAdd);
}
/**
* Returns the value removed from the stack
* @return the value removed from the stack
*/
public String pop(){
try {
return Integer.toString(Coordinates.remove(0));
} catch (Exception e){
return null;
}
}
/**
* peeks into the stack
* @peeks into the stack
*/
public String peek(){
try {
return Integer.toString(Coordinates.get(0));
} catch (Exception e){
return null;
}
}
/**
* Returns coordinates stored in the stack
* @return coordinates stored in the stack
*/
public void PrintCoordinates(){
int index = Coordinates.size();
for(int element: Coordinates){
double Position = element * 1.0;
int YPos = (element - (int)(Math.ceil(Position / 12))) / 12;
int XPos = element - (YPos * 12);
System.out.print(index + ": YPos: " + YPos + " XPOS: " + XPos);
index--;
}
System.out.println();
}
/**
* Returns the size of the stack
* @return size of stack
*/
public int size(){
return Coordinates.size();
}
}