Skip to content

Commit

Permalink
Implement A-Jar
Browse files Browse the repository at this point in the history
  • Loading branch information
chrischenhui committed Aug 26, 2019
1 parent 85c9937 commit 5740102
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 16 deletions.
Binary file removed .build.gradle.swp
Binary file not shown.
6 changes: 2 additions & 4 deletions data/task.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
T | 1 | one thing
E | 0 | | 11/11/11 11:11
D | 0 | asd | 22/22/22 33:33
T | 0 | someting
T | 0 | something
D | 0 | asd | 11/11/11 11:11
6 changes: 3 additions & 3 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ public class Duke {
private TaskList tasks;
private Ui ui;

private Duke(String filePath) {
private Duke() {
ui = new Ui();
storage = new Storage(filePath);
storage = new Storage();
try {
tasks = new TaskList(storage.load());
} catch (DukeException e) {
Expand Down Expand Up @@ -39,6 +39,6 @@ private void run() {
}

public static void main(String[] args) {
new Duke("data/task.txt").run();
new Duke().run();
}
}
3 changes: 3 additions & 0 deletions src/main/java/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: Duke

29 changes: 21 additions & 8 deletions src/main/java/duke/util/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,24 @@
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Scanner;

public class Storage {
private Scanner sc;
private ArrayList<String> contentList = new ArrayList<String>();
private static final String DUKE_DATA_DIR = System.getProperty("user.home") + File.separator + "data";
private static final String DUKE_DATA_PATH = DUKE_DATA_DIR + File.separator + "task.txt";

public Storage(String filePath) {
public Storage() {
try {
File f = new File(filePath);
f.createNewFile();
if (!Paths.get(DUKE_DATA_PATH).toFile().exists()) {
Files.createDirectory(Paths.get(DUKE_DATA_DIR));
Files.createFile(Paths.get(DUKE_DATA_PATH));
}
File f = new File(DUKE_DATA_PATH);
sc = new Scanner(f);
} catch (FileNotFoundException e) {
System.out.println("You have no task.");
Expand All @@ -27,16 +34,22 @@ public Storage(String filePath) {
}

public ArrayList<String> load() {
while (sc.hasNext()) {
String s = sc.nextLine();
contentList.add(s);
try {
while (sc.hasNext()) {
String s = sc.nextLine();
contentList.add(s);
}
return contentList;
} catch (Exception e) {
System.out.println("No task were detected");
} finally {
return contentList;
}
return contentList;
}

public void save(ArrayList<Task> list) {
try {
FileWriter fw = new FileWriter("data/task.txt");
FileWriter fw = new FileWriter(DUKE_DATA_PATH);
String fileContent = "";
for (Task t : list) {
fileContent += t.toWriteFile() + "\n";
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/duke/util/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public class Ui {
private Scanner sc = new Scanner(System.in);
private String LINES = "____________________________________________________________\n";
private static final String LINES = "____________________________________________________________\n";

public Ui() {
}
Expand Down

0 comments on commit 5740102

Please sign in to comment.