Skip to content

Commit

Permalink
Duke commits
Browse files Browse the repository at this point in the history
  • Loading branch information
yuetong committed Mar 24, 2020
1 parent cb552cc commit 2dc13ec
Show file tree
Hide file tree
Showing 19 changed files with 26 additions and 37 deletions.
1 change: 1 addition & 0 deletions data/tasks.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
T|O|hi
2 changes: 1 addition & 1 deletion src/main/java/duke/duke/AddCommand.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package duke;
package duke.duke;

import java.time.LocalDate;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/duke/duke/ByeCommand.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package duke;
package duke.duke;

/**
* Follows command to exit programme.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/duke/duke/Command.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package duke;
package duke.duke;

public abstract class Command {
String str;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/duke/duke/Deadline.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package duke;
package duke.duke;

import java.time.LocalDate;
import java.text.SimpleDateFormat;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/duke/duke/DeleteCommand.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package duke;
package duke.duke;

/**
* Deletes task from tasklist from Duke.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/duke/duke/DoneCommand.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package duke;
package duke.duke;

/**
* Changes status of Task inside tasklist from Duke.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/duke/duke/Duke.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package duke;
package duke.duke;

/**
* Creates Duke Object with filepath.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/duke/duke/DukeException.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package duke;
package duke.duke;

/**
* Handles Exceptions.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/duke/duke/Event.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package duke;
package duke.duke;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/duke/duke/FindCommand.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package duke;
package duke.duke;

public class FindCommand extends Command {

Expand Down
7 changes: 4 additions & 3 deletions src/main/java/duke/duke/ListCommand.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package duke;
package duke.duke;

/**
* Lists the tasks from tasklist from Duke.
Expand All @@ -18,10 +18,11 @@ public class ListCommand extends Command {
* @return empty string
*/
String execute(TaskList lst,Storage storage,Ui ui,TasksNum tasks) {
String result = "";
for (int i = 0; i < lst.getSize(); i++) {
str += lst.getTask(i) + "\n";
result += lst.getTask(i) + "\n";
}
return str;
return result;
}

}
3 changes: 1 addition & 2 deletions src/main/java/duke/duke/Parser.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package duke;
package duke.duke;

/**
* Parses through user input to execute command.
Expand Down Expand Up @@ -27,7 +27,6 @@ public static Command parse(String str) throws DukeException {
String[] temp = str.split(" ");
switch (temp[0]) {
case "todo":
//System.out.println("Hi2");
return new AddCommand(str);
case "deadline":
return new AddCommand(str);
Expand Down
22 changes: 5 additions & 17 deletions src/main/java/duke/duke/Storage.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package duke;
package duke.duke;

import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand All @@ -13,7 +14,7 @@
* Creates Storage object.
*/
public class Storage {
private String directory = System.getProperty("user.dir");
private String directory = System.getProperty("user.home");
private String fileName = "tasks.txt";
private Path path = Paths.get(directory, "data", fileName);
private ArrayList<Task> lst = new ArrayList<Task>();
Expand All @@ -29,29 +30,24 @@ public ArrayList<Task> readFile() { //returns tasklist + task number (appended t
int tasks = 0;
if (!Files.exists(path)) {
try {
Files.createFile(path);
Files.createDirectories(path.getParent());
Files.write(path, new ArrayList<String>(), StandardCharsets.UTF_8);
} catch (IOException e) {
e.printStackTrace();
}
}
try {
List<String> input = Files.readAllLines(path);
//System.out.println(input.size());
for (int i = 0; i < input.size(); i++) {
//System.out.println(i);
tasks++;
String[] temp = input.get(i).split("\\|");
//is there a way to add different child class instances without 3 diff if-else statement
if (temp[0].equals("T")) {
//System.out.println("YO");
Todo todo = new Todo(temp[2]);
addtask(todo, temp[1], tasks);
lst.add(todo);
//System.out.println(lst.get(0));
} else {
//System.out.println(temp[0] + "HHEY");
//System.out.println(temp[1]);
//System.out.println(temp[2]);
LocalDate localdate = setDate(temp[3]);
if (temp[0].equals("D")) {
Deadline deadline = new Deadline(temp[2], localdate);
Expand All @@ -69,11 +65,9 @@ public ArrayList<Task> readFile() { //returns tasklist + task number (appended t
Todo todo = new Todo(Integer.toString(tasks)); //dummy Todo for tasksnum
todo.doAct();
lst.add(todo);//add in tasknum
System.out.println("Added");
} catch (IOException e) {
e.printStackTrace();
}
//System.out.println(lst.get(0));
return lst;
}

Expand All @@ -82,15 +76,12 @@ public ArrayList<Task> readFile() { //returns tasklist + task number (appended t
* @param lst from Tasklist from ByeCommand
*/
public void writeToFile(TaskList lst) {
//System.out.println("HEYY");
try {
BufferedWriter writer = Files.newBufferedWriter(path);;
for (int i = 0; i < lst.getSize(); i++) {
//System.out.println("HEYY");
Task task = lst.getTask(i);
if (task instanceof Todo) {
writer.write("T" + "|" + task.getStatusIcon() + "|" + task.getD());
//System.out.println("HEYY");
writer.newLine();
} else {
writer.write(task.getType() + "|" + task.getStatusIcon() + "|"
Expand All @@ -100,7 +91,6 @@ public void writeToFile(TaskList lst) {
}
writer.flush();
writer.close();
//System.out.println("HEYY");
} catch (IOException e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -128,10 +118,8 @@ private LocalDate setDate(String date) {
*/
private void addtask(Task task, String status, int tasks) {
if (status.equals("O")) {
System.out.println("Done");
task.doAct();
tasks--;
System.out.println(tasks + "fuck");
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/duke/duke/Task.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package duke;
package duke.duke;

public class Task {
protected String description;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/duke/duke/TaskList.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package duke;
package duke.duke;

import java.util.ArrayList;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/duke/duke/TasksNum.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package duke;
package duke.duke;

/**
* Stores number of tasks remaining for users.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/duke/duke/Todo.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package duke;
package duke.duke;

public class Todo extends Task {

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/duke/duke/Ui.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package duke;
package duke.duke;

import java.util.Scanner;

Expand Down

0 comments on commit 2dc13ec

Please sign in to comment.