forked from nus-cs2113-AY1920S2/duke
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Conflicts: # src/main/java/Duke.java # src/main/java/DukeExceptions.java # src/main/java/Parser.java
- Loading branch information
Showing
8 changed files
with
117 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,4 +54,5 @@ public boolean isDelete() { | |
String firstWord = getFirstWord(); | ||
return firstWord.equals("delete"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import java.io.File; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.io.FileNotFoundException; | ||
import java.util.Scanner; | ||
|
||
public class Storage{ | ||
protected File file; | ||
protected String filePath; | ||
protected ArrayList <Task> tasks; | ||
|
||
public Storage() { | ||
file = new File("store.txt"); | ||
filePath = file.getAbsolutePath(); | ||
} | ||
|
||
public void save(ArrayList <Task> tasks) { | ||
this.tasks = tasks; | ||
try { | ||
FileWriter fileWriter = new FileWriter(filePath); | ||
for (Task task : tasks) { | ||
fileWriter.write(task.storeText()); | ||
fileWriter.write(System.lineSeparator()); | ||
} | ||
fileWriter.close(); | ||
} catch (IOException exception) { | ||
System.out.println(" [Error " + exception.getMessage() + "] "); | ||
System.out.println(" Please contact the systems adminstrator for assistance"); | ||
} | ||
} | ||
|
||
public void restoreArray(Scanner fileReader, ArrayList <Task> tasksList) { | ||
while (fileReader.hasNextLine()) { | ||
String input = fileReader.nextLine(); | ||
String [] parameters = input.split(","); | ||
String type = parameters[0]; | ||
boolean isDone = Boolean.parseBoolean(parameters[1]); | ||
String description = parameters[2]; | ||
if (type.equals("[T]")) { | ||
ToDo existingToDo = new ToDo(description, isDone); | ||
tasksList.add(existingToDo); | ||
} else if (type.equals("[E]")) { | ||
String eventDetails = parameters[3]; | ||
Event existingEvent = new Event(description, isDone, eventDetails); | ||
tasksList.add(existingEvent); | ||
|
||
} else { | ||
String by = parameters[3]; | ||
Deadline existingDeadline = new Deadline(description, isDone, by); | ||
tasksList.add(existingDeadline); | ||
} | ||
} | ||
} | ||
|
||
public ArrayList <Task> loadTasks() { | ||
ArrayList <Task> tasksList = new ArrayList<Task>(); | ||
try { | ||
Scanner fileReader = new Scanner(file); | ||
restoreArray(fileReader, tasksList); | ||
fileReader.close(); | ||
} catch (FileNotFoundException exception) { | ||
System.out.println("file not found"); | ||
} | ||
return tasksList; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters