Skip to content

Commit

Permalink
Improved code coverage for certain use case
Browse files Browse the repository at this point in the history
Users previously may input wrong items for add task

Now gui will inform the specific problem

Duke.txt moved to resource folder
  • Loading branch information
yulonglim committed Sep 14, 2021
1 parent db716a6 commit 3623e91
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 28 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'

String javaFxVersion = '16'
String javaFxVersion = '11'

implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'win'
implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'mac'
Expand Down
9 changes: 9 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,12 @@ Task 1 in the list will be deleted
```
There are no task in your list
```
## FAQ

What if I want to change the type of task?

`As changing the type of task is a large change I believe that user should delete the task completely and add a new one!`

How will I know if I entered some fields wrongly?

`The GUI will automatically show error fields if there are errors in the input!`
24 changes: 12 additions & 12 deletions src/main/java/duke/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
import javafx.scene.control.TextField;

import java.io.IOException;
import java.util.ArrayList;

import static duke.Parser.taskParse;


public class Controller {

private static Storage storage = new Storage("C:\\Users\\65906\\IdeaProjects\\ip\\duke.txt");
private static Storage storage = new Storage("src/main/resources/duke.txt");
private static TaskList tasks;

@FXML
Expand Down Expand Up @@ -71,11 +70,7 @@ public void load(ActionEvent a) {
} catch (IOException | DukeException e) {
tasks = new TaskList();
}
String listContent = "";
for (int i = 0; i < tasks.size(); i++) {
listContent += (i + 1) + ". " + tasks.getTask(i).toString() + "\n";
}
listLabel.setText("Here are the tasks in your list:\n" + listContent);
listLabel.setText(tasks.toString());
}
}

Expand Down Expand Up @@ -110,12 +105,17 @@ public void add(ActionEvent a) {
this.load();
assert addTaskError.getText().equals("");
} else if (taskType.getText().equalsIgnoreCase("D") || taskType.getText().equalsIgnoreCase( "E")) {
tasks.addTask(taskParse(taskType.getText(), taskDescription.getText(),
taskDate.getValue().toString()));
this.load();
assert addTaskError.getText().equals("");
if (taskDate.getValue() == null) {
addTaskError.setText("Add a Date!");
} else {
tasks.addTask(taskParse(taskType.getText(),
taskDescription.getText(),
taskDate.getValue().toString()));
this.load();
assert addTaskError.getText().equals("");
}
} else {
addTaskError.setText("Wrong Format");
addTaskError.setText("Task type to be T, D or E");
}

}
Expand Down
23 changes: 8 additions & 15 deletions src/main/java/duke/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,15 @@ public Task getTask(int index) {
}

public void updateTask(int index, String description, LocalDate date) {
if (description.equalsIgnoreCase("")) {
if (date != null) {
if (this.list.get(index) instanceof Event) {
((Event) this.list.get(index)).changeDate(date);
} else if (this.list.get(index) instanceof Deadline) {
((Deadline) this.list.get(index)).changeDate(date);
}
}
} else {
this.list.get(index).markUndone();
if (!description.equalsIgnoreCase("")) {
this.getTask(index).changeDescription(description);
if (date != null) {
if (this.list.get(index) instanceof Event) {
((Event) this.list.get(index)).changeDate(date);
} else if (this.list.get(index) instanceof Deadline) {
((Deadline) this.list.get(index)).changeDate(date);
}
}
if (date != null) {
if (this.list.get(index) instanceof Event) {
((Event) this.list.get(index)).changeDate(date);
} else if (this.list.get(index) instanceof Deadline) {
((Deadline) this.list.get(index)).changeDate(date);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/duke.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
false|D|123|2021-09-16

0 comments on commit 3623e91

Please sign in to comment.