-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInbodyDataManager.java
More file actions
73 lines (62 loc) · 1.92 KB
/
InbodyDataManager.java
File metadata and controls
73 lines (62 loc) · 1.92 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
64
65
66
67
68
69
70
71
72
73
package 헬스파트너;
import java.io.*;
import java.util.Vector;
public class InbodyDataManager {
private static final String DATA_FILE = "inbody_data.txt";
private Vector<String> dates;
private Vector<Integer> scores;
public InbodyDataManager() {
dates = new Vector<>();
scores = new Vector<>();
loadDataFromFile();
}
public void addRecord(String date, int score) {
dates.add(date);
scores.add(score);
// 최대 7일간의 기록만 유지
if (dates.size() > 7) {
dates.remove(0);
scores.remove(0);
}
saveDataToFile();
}
public Vector<String> getDates() {
return new Vector<>(dates);
}
public Vector<Integer> getScores() {
return new Vector<>(scores);
}
public void clearData() {
dates.clear();
scores.clear();
saveDataToFile();
}
private void saveDataToFile() {
try (BufferedWriter writer = new BufferedWriter(new FileWriter(DATA_FILE))) {
for (int i = 0; i < dates.size(); i++) {
writer.write(dates.get(i) + "," + scores.get(i));
writer.newLine();
}
} catch (IOException e) {
e.printStackTrace();
}
}
private void loadDataFromFile() {
try (BufferedReader reader = new BufferedReader(new FileReader(DATA_FILE))) {
String line;
while ((line = reader.readLine()) != null) {
String[] parts = line.split(",");
dates.add(parts[0]);
scores.add(Integer.parseInt(parts[1]));
}
} catch (IOException e) {
// 파일이 없거나 읽기 오류 발생 시 무시
}
}
public void clearRecords() {
// 모든 인바디 기록 초기화
dates.clear();
scores.clear();
saveDataToFile(); // 파일에 저장
}
}