Skip to content

Commit

Permalink
Finalise KaTo
Browse files Browse the repository at this point in the history
  • Loading branch information
Shulong committed Sep 17, 2020
1 parent 6dab289 commit 92c2ab3
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 116 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins {
id 'java'
id 'application'
//id 'checkstyle'
id 'com.github.johnrengelman.shadow' version '5.1.0'
id "com.github.johnrengelman.shadow" version "6.0.0"
}

repositories {
Expand Down Expand Up @@ -46,7 +46,7 @@ test {
}

application {
mainClassName = "duke.Duke"
mainClassName = "duke.Launcher"
}

shadowJar {
Expand Down
5 changes: 0 additions & 5 deletions data/duke.txt
Original file line number Diff line number Diff line change
@@ -1,5 +0,0 @@
1.[DeadLine][✘] homework /by: Sep 09 2020
2.[Event][✓] play /at: Sep 09 2020
3.[ToDo][✓] fishing
4.[Event][✘] play /at: Sep 09 2020
5.[DeadLine][✘] finish 2103T ip work /by: Sep 18 2020
21 changes: 8 additions & 13 deletions src/main/java/duke/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class Duke extends Application {
private Image userBackground = new Image(this.getClass().getResourceAsStream("/images/background2.png"));
private Image dukeBackground = new Image(this.getClass().getResourceAsStream("/images/Sea.png"));

public Duke(){
public Duke() {
}

public Duke(String filePath) {
Expand All @@ -52,7 +52,7 @@ public Duke(String filePath) {
if (this.storage.load().isEmpty()) {
// create new task list if empty file
this.tasks = new TaskList();
}else{
} else {
this.tasks = new TaskList(storage.load());
}
}
Expand Down Expand Up @@ -97,20 +97,17 @@ public void start(Stage stage) {

}

private void setMainLayout(AnchorPane mainLayout, Button sendButton){
private void setMainLayout(AnchorPane mainLayout, Button sendButton) {
mainLayout.getChildren().addAll(scrollPane, userInput, sendButton);
mainLayout.setPrefSize(400.0, 600.0);
}

private void setUserInput(){
private void setUserInput() {
userInput.setPrefWidth(345.0);

userInput.setOnAction((event) -> {
handleUserInput();
});
userInput.setOnAction((event) -> handleUserInput());
}

private void setDialogContainer(){
private void setDialogContainer() {

// KaTo greats user in the chat window
Label dukeText = new Label("Hello, Ka To here, how can I serve you?");
Expand Down Expand Up @@ -155,7 +152,7 @@ private void setAnchorPane(Button button){

}

private void setSendButton(Button sendButton){
private void setSendButton(Button sendButton) {

sendButton.setPrefWidth(55.0);

Expand Down Expand Up @@ -195,7 +192,7 @@ private String getResponse(String input) {

if (this.storage.load().isEmpty()) {
this.tasks = new TaskList();
}else{
} else {
this.tasks = new TaskList(storage.load());
}
// get the KaTo response
Expand All @@ -204,8 +201,6 @@ private String getResponse(String input) {
return "Ka To: \n" + output;
}



public static void main(String[] args) {
String filePath = "./data/duke.txt";
Duke manager = new Duke(filePath);
Expand Down
28 changes: 14 additions & 14 deletions src/main/java/duke/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static void processCommand(String command, Ui ui, TaskList taskList, Stri
* Processes the command "tasks" and prints the task list
*/

private static void processTasksCommand(TaskList taskList, Ui ui){
private static void processTasksCommand(TaskList taskList, Ui ui) {
if (taskList.tasks.isEmpty()) {
ui.printEmptyList();
} else {
Expand All @@ -73,12 +73,12 @@ private static void processTasksCommand(TaskList taskList, Ui ui){
* Processes the command "done + number" and marks the relative task done
*/

private static void processDoneCommand(TaskList taskList, Ui ui, String filePath, String[] portions){
private static void processDoneCommand(TaskList taskList, Ui ui, String filePath, String[] portions) {
if (portions.length == 1) {
ui.failToMarkDone();
} else {
int taskNumber = Integer.parseInt(portions[1]);
if (taskNumber > taskList.taskCounts) {
if (taskNumber < 1 || taskNumber > taskList.taskCounts) {
ui.failToFindTask();
} else {
Task task = taskList.tasks.get(taskNumber - 1);
Expand All @@ -93,12 +93,12 @@ private static void processDoneCommand(TaskList taskList, Ui ui, String filePath
* Processes the command "delete + number" and deletes the relative task
*/

private static void processDeleteCommand(TaskList taskList, Ui ui, String filePath, String[] portions){
private static void processDeleteCommand(TaskList taskList, Ui ui, String filePath, String[] portions) {
if (portions.length == 1) {
ui.failToDelete();
} else {
int taskNumber = Integer.parseInt(portions[1]);
if (taskNumber > taskList.taskCounts) {
if (taskNumber < 1 || taskNumber > taskList.taskCounts) {
ui.failToFindTask();
} else {
Task task = taskList.tasks.get(taskNumber - 1);
Expand Down Expand Up @@ -127,7 +127,7 @@ private static void processFindCommand(TaskList taskList, Ui ui, String[] portio
* Updates the storage if task is valid
*/

private static void processToDoCommand(TaskList taskList, Ui ui, String[] portions, String filePath){
private static void processToDoCommand(TaskList taskList, Ui ui, String[] portions, String filePath) {
boolean isCorrectCommand = true;

if (portions.length == 1) {
Expand All @@ -140,16 +140,16 @@ private static void processToDoCommand(TaskList taskList, Ui ui, String[] portio

boolean hasDuplicates = false;
//find duplicates
for(int i = 0; i < taskList.taskCounts; i++){
for (int i = 0; i < taskList.taskCounts; i++) {
if (taskList.tasks.get(i).toString().equals(toDo.toString())) {
hasDuplicates = true;
break;
}
}
//add task if no duplicates
if(hasDuplicates){
if (hasDuplicates) {
ui.findDuplicates();
}else {
} else {
taskList.addTask(toDo);
ui.addTaskSuccessful(toDo, taskList);
}
Expand All @@ -162,7 +162,7 @@ private static void processToDoCommand(TaskList taskList, Ui ui, String[] portio
* updates the storage if the task is valid
*/

private static void processDeadlineCommand(TaskList taskList, Ui ui, String[] portions, String filePath){
private static void processDeadlineCommand(TaskList taskList, Ui ui, String[] portions, String filePath) {
boolean isCorrectCommand = true;
boolean includesTime = false;
String detail = "";
Expand All @@ -172,12 +172,12 @@ private static void processDeadlineCommand(TaskList taskList, Ui ui, String[] po
isCorrectCommand = false;
}

if(isCorrectCommand){
if (isCorrectCommand) {
String[] deadlineSplitter = portions[1].split("/by ");
if (deadlineSplitter.length == 1) {
ui.failToFindTime();

}else {
} else {
detail = deadlineSplitter[0];
date = deadlineSplitter[1];
includesTime = true;
Expand All @@ -196,9 +196,9 @@ private static void processDeadlineCommand(TaskList taskList, Ui ui, String[] po
}
}
//add task if no duplicates
if(hasDuplicates){
if (hasDuplicates) {
ui.findDuplicates();
}else {
} else {
taskList.addTask(deadline);
ui.addTaskSuccessful(deadline, taskList);
}
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/duke/ParserGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private static String processDoneCommand(TaskList taskList, GUI ui, String fileP
return ui.failToMarkDone();
} else {
int taskNumber = Integer.parseInt(portions[1]);
if (taskNumber > taskList.taskCounts) {
if (taskNumber < 1 || taskNumber > taskList.taskCounts) {
return ui.failToFindTask();
} else {
Task task = taskList.tasks.get(taskNumber - 1);
Expand All @@ -106,7 +106,7 @@ private static String processDeleteCommand(TaskList taskList, GUI ui, String fil
return ui.failToDelete();
} else {
int taskNumber = Integer.parseInt(portions[1]);
if (taskNumber > taskList.taskCounts) {
if (taskNumber < 1 || taskNumber > taskList.taskCounts) {
return ui.failToFindTask();
} else {
Task task = taskList.tasks.get(taskNumber - 1);
Expand Down Expand Up @@ -209,7 +209,6 @@ private static String processEventCommand(TaskList taskList, GUI ui, String[] po
return ui.failToFindDetails();
}


String[] eventSplitter = portions[1].split("/at ");
if (eventSplitter.length == 1) {
return ui.failToFindTime();
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/duke/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public List<String> load() {
while (myReader.hasNextLine()) {
String data = myReader.nextLine();
inputs.add(data);

}
myReader.close();
} catch (FileNotFoundException e) {
Expand All @@ -54,7 +53,6 @@ public List<String> load() {
Files.createDirectories(path);

System.out.println("Directory is created!");

} catch (IOException error) {
System.err.println("Failed to create directory!" + error.getMessage());
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/duke/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public Task(int category, int status, String command) {


public String getStatusIcon() {
return ((this.status == DONE) ? "\u2713" : "\u2718");
return ((this.status == DONE) ? "v" : "x");
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/duke/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public TaskList(List<String> data) {
assert commandPortions.length > 2 : "incorrect command portions";
String mark = commandPortions[1].substring(commandPortions[1].length() - 1);

int status = (mark.equals("\u2713")) ? Task.DONE : Task.DOING;
int status = (mark.equals("v")) ? Task.DONE : Task.DOING;
String commandDetails = commandPortions[2].substring(1);
Task task = new Task(0, 0, "");

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/duke/ToDo.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ public ToDo(int category, int status, String command) {
super(category, status, command);
}

@Override
public String toString() {
return super.toString();
}
}
6 changes: 5 additions & 1 deletion src/main/java/duke/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,16 @@ public void findDuplicates() {
* @param taskList TaskList taskList to be searched within
*/

public void printFound(String keyWord, TaskList taskList){
public void printFound(String keyWord, TaskList taskList) {

for (int i = 1; i < taskList.taskCounts + 1; i++) {

Task task = taskList.tasks.get(i - 1);

if (task.toString().contains(keyWord)) {
System.out.println("" + i + "." + task);
}

}
}
}
2 changes: 1 addition & 1 deletion src/test/java/duke/DeadlineTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class DeadlineTest {
@Test
public void DeadlineTest(){
Deadline deadline = new Deadline(Task.TASK_DEADLINE, Task.DONE, "Homework", "2020-09-03");
assertEquals(deadline.toString(), "[DeadLine][] Homework(by: Sep 03 2020)");
assertEquals(deadline.toString(), "[DeadLine][v] Homework/by: Sep 03 2020");

}
}
3 changes: 2 additions & 1 deletion src/test/java/duke/ToDoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class ToDoTest {
@Test
public void ToDoTest(){
ToDo toDo = new ToDo(Task.TASK_TODO, Task.DONE, "Homework");
assertEquals(toDo.toString(), "[ToDo][✓] Homework");
assertEquals(toDo.toString(), "[ToDo][v] Homework");

}
}
70 changes: 0 additions & 70 deletions text-ui-test/EXPECTED.TXT
Original file line number Diff line number Diff line change
@@ -1,70 +0,0 @@
Hello from
____ _
| _ \ _ _| | _____
| | | | | | | |/ / _ \
| |_| | |_| | < __/
|____/ \__,_|_|\_\___|

____________________________________________________________
Hello :))! I'm your daily manager, Ka To! Welcome Back!
how could I serve you now?
You could ask me any question if you like!
____________________________________________________________
oops, the todo description cannot be empty
oops, the deadline description cannot be empty
oops, the event description cannot be empty
Ka To:

Sorry, I could not answer that
Ka To:

You have not given me any task yet
Ka To:

Only an apple pie
Ka To:

I have checked, it is 20000 SGD
Ka To:

1. [x] food left
2. [x] allowance left
Ka To:

Yup, this is now added! [T][x] watch a movie
You have 3 task added now!
Ka To:

Yup, this is now added! [D][x] my homework (by: tonight)
You have 4 task added now!
Ka To:

Yup, this is now added! [E][x] meet my friend (at: lunchtime)
You have 5 task added now!
Ka To:

Wow, this is now solved! [v] allowance left
Ka To:

Wow, this is now solved! [v] my homework (by: tonight)
Ka To:

1. [x] food left
2. [v] allowance left
3. [T][x] watch a movie
4. [D][v] my homework (by: tonight)
5. [E][x] meet my friend (at: lunchtime)
Ka To:

Noted, this is now deleted! [v] allowance left
Ka To:

Noted, this is now deleted! [x] meet my friend (at: lunchtime)
Ka To:

1. [x] food left
2. [T][x] watch a movie
3. [D][v] my homework (by: tonight)
Ka To:

I am happy to serve you. See you soon!
10 changes: 10 additions & 0 deletions text-ui-test/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
food
allowance
tasks
todo ip project
deadline ip /by 2020-09-16
event tp /at 2020-09-17
done 2
delete 2
find ip
bye

0 comments on commit 92c2ab3

Please sign in to comment.