Skip to content

Commit 3a81cc7

Browse files
committed
Merge branch 'branch-Level-7'
2 parents 84f3106 + 0371c15 commit 3a81cc7

File tree

6 files changed

+58
-2
lines changed

6 files changed

+58
-2
lines changed

src/main/java/Duke.java

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ public static void main(String[] args) {
1010
String goodbye = horLine +
1111
"\n Bye. Hope to see you again soon!\n" + horLine;
1212

13+
TaskType list = new TaskType();
14+
FileAccess fileAccess = new FileAccess(list);
15+
fileAccess.writeToFile();
16+
1317
// print hello message
1418
System.out.println(hello);
1519

src/main/java/Event.java

+6
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,10 @@ public Event(String description, String at) {
1111
public String toString() {
1212
return "[E]" + super.toString() + " (at: " + this.at + ")";
1313
}
14+
public String getType() {
15+
return "E";
16+
}
17+
public String getTime() {
18+
return at;
19+
}
1420
}

src/main/java/FileAccess.java

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import java.io.FileWriter;
2+
import java.io.IOException;
3+
4+
public class FileAccess {
5+
private static final String FILE_PATH = "./docs/duke.txt";
6+
7+
private final TaskType taskType;
8+
9+
public FileAccess (TaskType list) {
10+
this.taskType = list;
11+
}
12+
public void writeToFile () {
13+
try {
14+
FileWriter fw = new FileWriter(FILE_PATH);
15+
16+
for (Task task : taskType.getTasks()) {
17+
fw.write(task.getType() + " | " +
18+
task.getStatusIcon() + " | " +
19+
task.getDescription() + " | " +
20+
task.getTime() + System.lineSeparator());
21+
}
22+
fw.close();
23+
} catch (IOException e) {
24+
System.out.println("An error has occurred!");
25+
e.printStackTrace();
26+
}
27+
}
28+
}

src/main/java/Task.java

+8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ public String getDescription() {
1515
return description;
1616
}
1717

18+
public String getType() {
19+
return "type";
20+
}
21+
22+
public String getTime() {
23+
return "by/at";
24+
}
25+
1826
public int getId() {
1927
return id;
2028
}

src/main/java/TaskType.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,8 @@ public void listTasks() {
4747
System.out.println(" " + (i + 1) + "." + " " + tasks.get(i).toString());
4848
}
4949
}
50-
}
50+
51+
public ArrayList<Task> getTasks() {
52+
return tasks;
53+
}
54+
}

src/main/java/Todo.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,10 @@ public Todo(String description) {
88
public String toString() {
99
return "[T]" + super.toString();
1010
}
11-
}
11+
public String getType() {
12+
return "T";
13+
}
14+
public String getTime() {
15+
return "";
16+
}
17+
}

0 commit comments

Comments
 (0)