-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBrudnopis.java
More file actions
44 lines (37 loc) · 899 Bytes
/
Brudnopis.java
File metadata and controls
44 lines (37 loc) · 899 Bytes
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
package com;
import java.util.Arrays;
import java.util.List;
class Brudnopis {
private List<String> snapShots;
private Integer nr = 0;
private int undoCount = 0;
Brudnopis() {
snapShots = Arrays.asList("", "", "", "", "", "", "", "", "", "");
}
String getState() {
return snapShots.get(nr);
}
void newState(String str) {
undoCount = 0;
nr = (nr + 1) % 10;
snapShots.set(nr, str);
}
void prevState() {
if(undoCount == 9) {
System.out.println("Cannot UNDO anymore!\n");
return;
}
nr = (nr - 1) % 10;
if(nr == -1)
nr = 9;
undoCount++;
}
void nextState() {
if(undoCount > 0){
nr = (nr + 1) % 10;
undoCount--;
}else{
System.out.println("Cannot REDO anymore!\n");
}
}
}