Skip to content

Commit

Permalink
C-Archive
Browse files Browse the repository at this point in the history
  • Loading branch information
gx-huang committed Feb 11, 2020
1 parent 86b194f commit 37dbac6
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 33 deletions.
8 changes: 5 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import org.gradle.api.plugins.internal.DefaultJavaApplication
import org.gradle.internal.jvm.Jvm


plugins {
id 'java'
Expand Down Expand Up @@ -53,8 +52,11 @@ dependencies {
implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'win'
implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'mac'
implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'linux'

compile files("${System.properties['JAVA_HOME']}/../lib/tools.jar")
}

run {
standardInput = System.in
}
}

2 changes: 1 addition & 1 deletion src/main/java/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void start(Stage stage) {
// You will need to import `javafx.scene.layout.Region` for this.
dialogContainer.setPrefHeight(Region.USE_COMPUTED_SIZE);

userInput.setPrefWidth(500.0);
userInput.setPrefWidth(480.0);

sendButton.setPrefWidth(55.0);

Expand Down
28 changes: 19 additions & 9 deletions src/main/java/DukeParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,42 +35,52 @@ public String parseCommand(String command) {

String context = command_broken[1];
int taskNo = Integer.parseInt(context);
tasks.removeTask(taskNo);
return DukeUI.showDeleteMsg();
return tasks.removeTask(taskNo);

} else if (action.equalsIgnoreCase(("deadline"))) {

String context = command_broken[1];
String[] context_broken = context.split(" /by ", 2);
tasks.addInput(new Deadlines(context_broken[0], false ,context_broken[1]));
return DukeUI.showCreationMsg();
Task tempTask = tasks.addTask(new Deadlines(context_broken[0], false ,context_broken[1]));
return DukeUI.showCreationMsg(tempTask);

} else if (action.equalsIgnoreCase(("todo"))) {

if (command_broken.length == 1) {
throw new DukeException("THE DESCRIPTION OF TODO CANNOT BE EMPTY");
}
tasks.addInput(new ToDos(command_broken[1], false));
return DukeUI.showCreationMsg();
Task tempTask = tasks.addTask(new ToDos(command_broken[1], false));
return DukeUI.showCreationMsg(tempTask);

} else if (action.equalsIgnoreCase(("event"))) {

String context = command_broken[1];
String[] context_broken = context.split(" /at ", 2);
tasks.addInput(new Events(context_broken[0], false, context_broken[1]));
return DukeUI.showCreationMsg();
Task tempTask = tasks.addTask(new Events(context_broken[0], false, context_broken[1]));
return DukeUI.showCreationMsg(tempTask);

} else if (action.equalsIgnoreCase("find")) {

int count = 1;
for (Task t: tasks.getAllTasks()) {
for (Task t : tasks.getAllTasks()) {
if (t.containsSubstring(command_broken[1])) {
System.out.println(count + "." + t);
count++;
}
}
return DukeUI.showFindMsg();
} else if (action.equalsIgnoreCase("archive")) {

String context = command_broken[1];
int taskNo = Integer.parseInt(context);
return tasks.archiveTask(taskNo);

} else if (action.equalsIgnoreCase("archiveall")) {

return tasks.archiveAll();

} else if (action.equalsIgnoreCase("showarchive")){
return tasks.showArchived();
} else {
return "UNABLE TO COMPREHEND";
}
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/DukeUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ public static String showLoadingError() {
public static String showDoneMsg() {
return "TASK COMPLETED";
}
public static String showCreationMsg() {
return "UNDERSTOOD";

public static String showCreationMsg(Task task) {
return "UNDERSTOOD \n" + task.toString() + "\nADDED";
}

public static String showDeleteMsg() {
Expand All @@ -41,5 +42,11 @@ public static String showFindMsg() {
}

public static String showCurrentListSize(int size) {
return "NOW YOU HAVE " + size + " TASKS";}
return "NOW YOU HAVE " + size + " TASKS";
}

public static String showArchivedMsg(Task task) {
return task.toString() + "\n IS NOW ARCHIVED";
}

}
52 changes: 39 additions & 13 deletions src/main/java/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,20 @@
//Wrapper class for the list of tasks
public class TaskList {
private List<Task> allTasks;
private List<Task> archivedTasks;

public TaskList() {
allTasks = new ArrayList<>();
archivedTasks = new ArrayList<>();
}

public void addInput(Task s) {
public Task addTask(Task s) {
this.allTasks.add(s);
DukeUI.showCurrentListSize(allTasks.size());
return s;
}

public String printTasks() {
int count = 1;
StringBuilder sb = new StringBuilder();
sb.append("HERE IS YOUR LIST\n");
for (Task s : allTasks) {
sb.append( count+ ". " + s + "\n");
count++;
}
return sb.toString();
return getString(allTasks);
}

public Task getTask(int n) {
Expand All @@ -41,9 +36,40 @@ public void markDone(int taskNo) {
allTasks.get(taskNo - 1).markAsDone();
}

public void removeTask(int taskNo) {
public String removeTask(int taskNo) {
Task tempTask = allTasks.remove(taskNo - 1);
System.out.println(" " + tempTask);
DukeUI.showCurrentListSize(allTasks.size());
return DukeUI.showDeleteMsg() + "\n" +
" " + tempTask + "\n" +
DukeUI.showCurrentListSize(allTasks.size());
}

public String archiveTask(int taskNo) {
Task tempTask = allTasks.remove(taskNo - 1);
archivedTasks.add(tempTask);
return DukeUI.showArchivedMsg(tempTask);

}

public String archiveAll() {
String archiveMessage = "";
for (int i = 1; i <= allTasks.size(); i++) {
archiveMessage += this.archiveTask(i);
}
return archiveMessage;
}

public String showArchived() {
return getString(archivedTasks);
}

private String getString(List<Task> tasks) {
int count = 1;
StringBuilder sb = new StringBuilder();
sb.append("HERE IS YOUR LIST\n");
for (Task s : tasks) {
sb.append(count).append(". ").append(s).append("\n");
count++;
}
return sb.toString();
}
}
4 changes: 2 additions & 2 deletions src/test/java/DeadlineTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ public class DeadlineTest {

@Test
public void testStringConvert() {
assertEquals("[D][X] read book (By: JAN 1 2020)",
new Deadlines("read book",false, "2020-01-01").toString());
assertEquals("[D][O] read book (By: JAN 1 2020)",
new Deadlines("read book",false, "2020-01-01").toString());
assertEquals("[D][X] read book (By: JAN 1 2020)",
new Deadlines("read book", true, "2020-01-01").toString());
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/java/ToDoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ public class ToDoTest {

@Test
public void testStringConvert() {
assertEquals("[T][X] read book",
new ToDos("read book", false).toString());
assertEquals("[T][O] read book",
new ToDos("read book", false).toString());
assertEquals("[T][X] read book",
new ToDos("read book", true).toString());
}
}

0 comments on commit 37dbac6

Please sign in to comment.