forked from nus-cs2103-AY1920S1/duke
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added Parser, Ui, Storage, TaskList classes
- Loading branch information
Showing
5 changed files
with
186 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,27 @@ | ||
import java.lang.reflect.Array; | ||
|
||
public class Parser { | ||
private String line; | ||
private String inputString; | ||
private String command; | ||
private String taskDetails; | ||
|
||
public Parser(String line) { | ||
this.line = line; | ||
public Parser(String inputString) { | ||
this.inputString = inputString; | ||
} | ||
public String parse() { | ||
|
||
public void parse() { //cannot use "|" as a replacement | ||
String temp = this.inputString.replaceFirst(" ", ":"); | ||
System.out.println(temp); | ||
String[] tempArr = temp.split(":"); | ||
command = (String)Array.get(tempArr, 0); | ||
if(tempArr.length > 1) { //account for the fact that commands like "list" do not have task details | ||
taskDetails = ((String) Array.get(tempArr, 1)).trim(); | ||
} | ||
} | ||
public String getCommand() { | ||
return this.command; | ||
} | ||
public String getTaskDetails() { | ||
return this.taskDetails; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,54 @@ | ||
import java.lang.reflect.Array; | ||
import java.util.ArrayList; | ||
|
||
/** | ||
* Represents a taskList with the ability to perform features on the tasks within. | ||
*/ | ||
public class TaskList { | ||
private ArrayList<Task> tasks; | ||
private ArrayList<Task> listOfTasks; | ||
|
||
public TaskList(ArrayList<Task> tasks){ | ||
this.tasks = tasks; | ||
public TaskList(ArrayList<Task> listOfTasks) { | ||
this.listOfTasks = listOfTasks; | ||
} | ||
public TaskList() { | ||
this.tasks = new ArrayList<>(); | ||
this.listOfTasks = new ArrayList<>(); | ||
} | ||
|
||
public ArrayList<Task> getTasks() { | ||
return this.tasks; | ||
public ArrayList<Task> getListOfTasks() { | ||
return listOfTasks; | ||
} | ||
public void addTask(Task newTask) { | ||
listOfTasks.add(newTask); | ||
} | ||
public void deleteTask(int number) { | ||
Task temp = tasks.get(number - 1); | ||
tasks.remove(number - 1); | ||
Task temp = listOfTasks.get(number - 1); | ||
listOfTasks.remove(number - 1); | ||
} | ||
public void addTask (String taskType, String taskDetails) throws DukeException { | ||
if (taskDetails.equals("")) { | ||
throw new DukeException(" ☹ OOPS!!! The description of a " + taskType + " cannot be empty."); | ||
} | ||
if (taskType.equals("todo")) { | ||
this.tasks.add(new Todo(taskDetails)); | ||
} else if(taskType.equals("deadline") || taskType.equals("event")) { | ||
if(taskType.equals("deadline") || taskType.equals("event")) { | ||
//replace the first / so that the dates will not be split up | ||
taskDetails = taskDetails.replaceFirst("/", ":"); //need to assign this to taskDetails so it is re-recorded | ||
String[] tempStringArr = taskDetails.split(":"); | ||
String description = ((String) Array.get(tempStringArr, 0)).trim(); //to remove ending whitespace | ||
String secondString = ((String) Array.get(tempStringArr, 1)).substring(3); | ||
if (taskType.equals("deadline")) { | ||
tasks.add(new Deadline(description, secondString)); | ||
} else { | ||
tasks.add(new Event(description, secondString)); | ||
} | ||
} | ||
} else {//all other keywords not part of Duke's task handling schedule | ||
throw new DukeException(" ☹ OOPS!!! I'm sorry, but I don't know what that means :-("); | ||
|
||
public void printList() { | ||
int counter = 1; | ||
for (Task task : this.listOfTasks) { | ||
System.out.println(" " + counter + "." + task); | ||
counter++; | ||
} | ||
} | ||
|
||
/** | ||
* Sets a task in a specified position in listOfTasks as done. | ||
* | ||
* @param number Specified index of task.Task object in listOfTasks. | ||
*/ | ||
public void setTaskAsDone(int number) { | ||
Task temp = this.listOfTasks.get(number - 1); | ||
temp.setDone(); | ||
} | ||
|
||
/** | ||
* Returns a task.Task object in a specified position in listOfTasks. | ||
* | ||
* @param number Specified index of task.Task object in listOfTasks. | ||
* @return task.Task | ||
*/ | ||
public Task getTask(int number) { //what about case where it is empty? | ||
return this.listOfTasks.get(number); | ||
} | ||
} |
Oops, something went wrong.