Skip to content

Commit

Permalink
Merge pull request #83 from Deculsion/B-FixedDurationTasks
Browse files Browse the repository at this point in the history
[CS2113-F09-3]-Deculsion-B-FixedDurationTasks
  • Loading branch information
cyanoei authored Sep 19, 2019
2 parents 5293906 + 5ee651d commit 06d923a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 8 deletions.
4 changes: 1 addition & 3 deletions data/saved_tasks.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
4/D/1/x /04/05/2000 2000
5/E/0/project meeting /19/9/2019 1000
6/T/0/sleep
4/D/1/x /04/05/2000 2000
12 changes: 8 additions & 4 deletions src/main/java/duke/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@

public class Parser {

private String addTodo(String input) throws InsufficientInfoException {
private String[] addTodo(String input) throws InsufficientInfoException {
if (input.isBlank()) {
throw new InsufficientInfoException("Sorry, the description of a Todo cannot be blank!");
} else {
return input;
}

String[] checkHours = input.split(" /needs ", -1);

return checkHours;

}

private String[] addDeadline(String input) throws InsufficientInfoException {
Expand Down Expand Up @@ -89,7 +92,8 @@ private Command handleListInput(String listInput) throws BadInputException,

//Commands which require string input.
case "todo":
command = new AddCommand(Command.CommandType.TODO, addTodo(keyword[1]), null);
String[] todoTemp = addTodo(keyword[1]);
command = new AddCommand(Command.CommandType.TODO, todoTemp[0], (todoTemp.length > 1) ? todoTemp[1] : "");
break;
case "deadline": {
String[] temp = addDeadline(keyword[1]);
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/duke/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ public void addTodoItem(int index, String todoitem) {
setListIndex(index + 1); //Next open index.
}

/**
* Adds a todo item to the list but with duration.
* @param todoitem description of the task.
* @param hours duration of task.
*/
public void addTodoItem(int index, String todoitem, int hours) {
taskList.add(new Todo(index, todoitem, hours)); //Use the constructor to create a new Task.
System.out.println("Todo item added: " + todoitem);
System.out.println("Hours needed: " + hours);
setListIndex(index + 1); //Next open index.
}

/**
* Adds a deadline item to the list and prints a confirmation.
*
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/duke/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ public void execute(TaskList list, Ui ui, Storage storage) {
int index = list.getListIndex();

if (super.type == CommandType.TODO) {
list.addTodoItem(index, description);
if (!details.equals("")) {
list.addTodoItem(index, description, Integer.parseInt(details));
} else {
list.addTodoItem(index, description);
}
} else if (super.type == CommandType.DEADLINE) {
list.addDeadlineItem(index, description, details);
} else { //Type is event
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/duke/items/Todo.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,27 @@

public class Todo extends Task {

private int duration = 0;

public Todo(int index, String description) {
super(index, description, TaskType.TODO); //Using the Task constructor. isDone is set to false.
}

public Todo(int index, String description, int duration) {
super(index, description, TaskType.TODO);
this.duration = duration;
}

@Override
public String saveDetailsString() {
return super.saveDetailsString();
}

@Override
public String toString() {
if (duration > 0) {
return super.toString() + " (needs " + duration + "hours)";
}
return super.toString();
}
}

0 comments on commit 06d923a

Please sign in to comment.