-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActivityLog.java
More file actions
40 lines (35 loc) · 1.12 KB
/
ActivityLog.java
File metadata and controls
40 lines (35 loc) · 1.12 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
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class ActivityLog {
private Node<String> head;
private Node<String> tail;
public ActivityLog() {
this.head = null;
this.tail = null;
}
public void addLog(String activity) {
String timestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
String logEntry = "[" + timestamp + "] " + activity;
Node<String> newNode = new Node<>(logEntry);
if (tail == null) {
head = tail = newNode;
} else {
tail.next = newNode;
newNode.prev = tail;
tail = newNode;
}
}
public void printLogs() {
System.out.println("\n--- Log Aktivitas ---");
if (head == null) {
System.out.println("Tidak ada aktivitas yang tercatat.");
return;
}
Node<String> current = head;
while (current != null) {
System.out.println(current.data);
current = current.next;
}
System.out.println("------------------------\n");
}
}