-
Notifications
You must be signed in to change notification settings - Fork 267
[KristopherPTaslim] iP #287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
KristopherPTaslim
wants to merge
39
commits into
nus-cs2103-AY2122S2:master
Choose a base branch
from
KristopherPTaslim:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 12 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
d839859
Add Gradle support
5406049
Level-1
KristopherPTaslim 0dd972e
Finish Level-2
KristopherPTaslim 1812262
Finish Level-3
KristopherPTaslim 277c43f
Finish Level-4
KristopherPTaslim 73b1d1c
Finish Level-5
KristopherPTaslim d619a83
Finish Level-6
KristopherPTaslim 318b3aa
Finish Testing
KristopherPTaslim 32bb23a
Finish Branch-Level-7
KristopherPTaslim bc9608c
Finish branch-Level-8
KristopherPTaslim e754bcb
Merge branch 'branch-Level-8'
KristopherPTaslim b37f27b
Debug Branch Level-7
KristopherPTaslim 83bb0f3
Finish A-MOREOOP
KristopherPTaslim 27fc406
Finish A-Packages
KristopherPTaslim 589b161
Finish A-JUnit
KristopherPTaslim e8b6b2a
Debug A-JUnit
KristopherPTaslim 28a85db
Delete the wrong folder test:java:duke
KristopherPTaslim 7bbe7be
Finish A-Javadoc
KristopherPTaslim 7b43639
Added missing JavaDoc in the branch-A-JavaDoc
KristopherPTaslim bbc3057
Finish A-CodingStandard
KristopherPTaslim 6ea1b8c
Finish branch-Level-9
KristopherPTaslim 3d551ba
Merge tag 'branch-A-CodingStandard'
KristopherPTaslim 452a916
Merge tag 'branch-Level-9'
KristopherPTaslim aa60d80
Merging all the three branches(JavaDoc, Coding Standard and Level 9)
KristopherPTaslim 6b75a3c
Merge commit 'd8398594b7bc43da5eb865321c5a50cec4b3923d' into branch-A…
KristopherPTaslim 725a458
Finish running branch-A-Gradle
KristopherPTaslim fd68d86
Finish Level-10
KristopherPTaslim 80a985b
Fix Minor Bug
KristopherPTaslim 4524860
Edit execute() method in Parser class to follow coding standard.
KristopherPTaslim adc7846
Add assertions in some various points in code
KristopherPTaslim c3d28a2
Merge pull request #2 from KristopherPTaslim/branch-A-Assertions
KristopherPTaslim 97d12b1
Merge branch 'master' into branch-A-CodeQuality
KristopherPTaslim 1dfa71f
Merge pull request #3 from KristopherPTaslim/branch-A-CodeQuality
KristopherPTaslim c96d62b
Edit minor feature in Parser class
KristopherPTaslim 36ccfcc
Finish branch-BCD-Extension
KristopherPTaslim 99300b0
Add Ui.png under the docs folder
KristopherPTaslim 7e5a187
Update ReadME.md
KristopherPTaslim cc38eb8
Update ReadME.md
KristopherPTaslim 1a329c8
Edit some parts in build.gradle
KristopherPTaslim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| class Deadline extends Task { | ||
|
|
||
| protected String by; | ||
|
|
||
| public Deadline(String description, String by) { | ||
| super(description); | ||
| this.by = by; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "[D]" + super.toString() + "(by: " + by + ")"; | ||
| } | ||
|
|
||
| @Override | ||
| public String getInitial() { | ||
| return "[D]"; | ||
| } | ||
| } |
This file contains hidden or 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,10 +1,45 @@ | ||
| import java.io.IOException; | ||
| import java.util.Scanner; | ||
|
|
||
| public class Duke { | ||
|
|
||
| private Storage storage; | ||
| private TaskList taskList; | ||
| private Ui ui; | ||
|
|
||
| public Duke(String filePath) { | ||
| this.ui = new Ui(); | ||
| this.storage = new Storage(filePath); | ||
| this.taskList = new TaskList(storage); | ||
| } | ||
|
|
||
| public void run() { | ||
| ui.showWelcomeMessage(); | ||
| try { | ||
| Scanner sc = new Scanner(storage.load()); | ||
| String input = sc.nextLine(); | ||
| Parser parser = new Parser(taskList); | ||
|
|
||
| while (sc.hasNextLine()) { | ||
| parser.execute(input); | ||
| if (input.toLowerCase().equals("bye")) { | ||
| break; | ||
| } | ||
| input = sc.nextLine(); | ||
| } | ||
|
|
||
| } catch (IOException e) { | ||
| System.out.println("File is not found :(!"); | ||
| } | ||
|
|
||
| storage.writeFile(); | ||
| } | ||
|
|
||
| public static void main(String[] args) { | ||
| String logo = " ____ _ \n" | ||
| + "| _ \\ _ _| | _____ \n" | ||
| + "| | | | | | | |/ / _ \\\n" | ||
| + "| |_| | |_| | < __/\n" | ||
| + "|____/ \\__,_|_|\\_\\___|\n"; | ||
| System.out.println("Hello from\n" + logo); | ||
| Duke duke = new Duke("/data/tasks.txt"); | ||
| duke.run(); | ||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| class DukeException extends RuntimeException { | ||
|
|
||
| public DukeException(String Message) { | ||
| super(Message); | ||
| } | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| class Event extends Task { | ||
|
|
||
| protected String at; | ||
|
|
||
| public Event(String description, String at) { | ||
| super(description); | ||
| this.at = at; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "[E]" + super.toString() + "(at: " + at + ")"; | ||
| } | ||
|
|
||
| @Override | ||
| public String getInitial() { | ||
| return "[E]"; | ||
| } | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.nio.file.Paths; | ||
| import java.io.FileWriter; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
|
|
||
| class FileClass { | ||
|
|
||
| public void createFile(String filePath) { | ||
| File f = new File(filePath); //initialise the file | ||
| if (!f.exists()) { //meaning f doesnt exist | ||
| try { | ||
| f.createNewFile(); | ||
| } catch (IOException e) { | ||
| System.out.println("Path Directory is invalid!"); | ||
| } | ||
| } | ||
| } | ||
| //taken from W3.3c File Access | ||
| public void writeFile(String filePath, String textToAdd) throws IOException { | ||
| FileWriter fw = new FileWriter(filePath, true); // initialise the filewriter | ||
| fw.write(textToAdd + "\r\n"); | ||
| fw.close(); | ||
| } | ||
|
|
||
| public void createDirectory(String filePath) { | ||
| File f = new File(filePath); //initialise the file | ||
| Path path = Paths.get(filePath); | ||
| if (!f.exists()) { //meaning f doesnt exist | ||
| try { | ||
| Files.createDirectory(path); | ||
| } catch (IOException e) { | ||
| System.out.println("Path Directory cannot be created!"); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| } | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| import java.time.LocalDateTime; | ||
| import java.time.format.DateTimeFormatter; | ||
|
|
||
| class Parser { | ||
| public TaskList taskList; | ||
| private Ui ui; | ||
|
|
||
| Parser(TaskList taskList) { | ||
| this.taskList = taskList; | ||
| this.ui = new Ui(); | ||
| } | ||
|
|
||
| public void execute(String input) { | ||
| String[] checkCase = input.split(" "); | ||
| switch (checkCase[0].toLowerCase()) { | ||
|
|
||
| case ("list"): | ||
| ui.showListMessage(taskList); | ||
| break; | ||
|
|
||
| case ("mark"): | ||
| try { | ||
| int index = Integer.parseInt(checkCase[1]) - 1; | ||
| Task tasks = taskList.getTaskArray().get(index); | ||
| System.out.println(tasks.marking(checkCase[0].toLowerCase())); | ||
| taskList.getTaskArray().set(index, tasks); | ||
| } catch (ArrayIndexOutOfBoundsException e) { | ||
| ui.showInvalidInput(); | ||
| } | ||
| break; | ||
|
|
||
| case ("unmark"): | ||
| try { | ||
| int index = Integer.parseInt(checkCase[1]) - 1; | ||
| Task tasks = taskList.getTaskArray().get(index); | ||
| System.out.println(tasks.marking(checkCase[0].toLowerCase())); | ||
| taskList.getTaskArray().set(index, tasks); | ||
| } catch (ArrayIndexOutOfBoundsException e) { | ||
| ui.showInvalidInput(); | ||
| } | ||
| break; | ||
|
|
||
| case ("todo"): | ||
|
|
||
| try { | ||
| String toDoCondition = "todo "; | ||
| int indexOfToDo = toDoCondition.length(); //to find todo | ||
| String stringSliced = input.substring(indexOfToDo,input.length()); | ||
| Todo todoTask = new Todo(stringSliced); | ||
| taskList.addTask(todoTask); | ||
| String noOfTask = String.valueOf(taskList.getTaskArray().size()); | ||
| ui.showAddedMessage(todoTask, noOfTask); | ||
| } catch (StringIndexOutOfBoundsException e) { | ||
| ui.showTodoError(); | ||
| } | ||
| break; | ||
|
|
||
| case ("deadline"): | ||
|
|
||
| try { | ||
| String deadlineCondition = "/by "; | ||
| int indexOfTime = input.indexOf(deadlineCondition); //to find / | ||
| String dateTime = input.substring(indexOfTime + deadlineCondition.length(), input.length()); // the date and time for by | ||
| //convert to the correct one | ||
| LocalDateTime deadlineTime = LocalDateTime.parse(dateTime, DateTimeFormatter.ofPattern("d/M/y Hmm")); | ||
| String convertedTime = deadlineTime.format(DateTimeFormatter.ofPattern("MMM d yyyy hh:mm a")); | ||
| String stringSliced = input.substring(9, indexOfTime); // after deadline | ||
| Deadline deadlineTask = new Deadline(stringSliced, convertedTime); | ||
| taskList.addTask(deadlineTask); | ||
| String noOfTask = String.valueOf(taskList.getTaskArray().size()); | ||
| ui.showAddedMessage(deadlineTask, noOfTask); | ||
| } catch (StringIndexOutOfBoundsException e) { | ||
| ui.showDeadlineError(); | ||
| } | ||
| break; | ||
|
|
||
| case ("event"): | ||
|
|
||
| try { | ||
| String eventCondition = "/at "; | ||
| int indexOfTime = input.indexOf(eventCondition); //to find / | ||
| String dateTime = input.substring(indexOfTime + eventCondition.length(), input.length()); // the date and time for at | ||
| //convert to the correct one | ||
| LocalDateTime eventTime = LocalDateTime.parse(dateTime, DateTimeFormatter.ofPattern("d/M/y Hmm")); | ||
| String convertedTime = eventTime.format(DateTimeFormatter.ofPattern("MMM d yyyy hh:mm a")); | ||
| String stringSliced = input.substring(6, indexOfTime); // after deadline | ||
| Event eventTask = new Event(stringSliced, convertedTime); | ||
| taskList.addTask(eventTask); | ||
| String noOfTask = String.valueOf(taskList.getTaskArray().size()); | ||
| ui.showAddedMessage(eventTask, noOfTask); | ||
|
|
||
| } catch (StringIndexOutOfBoundsException e) { | ||
| ui.showEventError(); | ||
| } | ||
| break; | ||
|
|
||
| case("delete"): | ||
|
|
||
| try { | ||
| int index = Integer.parseInt(checkCase[1]) - 1; | ||
| Task task = taskList.getTaskArray().get(index); | ||
| taskList.deleteTask(index); | ||
| String noOfTask = String.valueOf(taskList.getTaskArray().size()); | ||
| ui.showDeletedMessage(task, noOfTask); | ||
| } catch (ArrayIndexOutOfBoundsException e) { | ||
| ui.showDeleteError(); | ||
| } | ||
| break; | ||
|
|
||
| case("bye"): | ||
| ui.showGoodbyeMessage(); | ||
| break; | ||
|
|
||
| default: | ||
| ui.showDefaultMessage(); | ||
| break; | ||
|
|
||
|
|
||
|
|
||
| } | ||
|
|
||
|
|
||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| } | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import java.util.ArrayList; | ||
| import java.io.File; | ||
| import java.io.IOException; | ||
|
|
||
| class Storage { | ||
| private ArrayList<Task> taskArray; | ||
| private String path; | ||
| private static String HOME = System.getProperty("user.home"); | ||
|
|
||
| Storage(String path) { | ||
| this.taskArray = new ArrayList<Task>(); | ||
| this.path = path; | ||
| } | ||
|
|
||
| public File load() { | ||
| FileClass fc = new FileClass(); //file class | ||
| String homePath = HOME + "/data"; | ||
| path = HOME + path; | ||
| fc.createDirectory(homePath); //create directory first | ||
| fc.createFile(path); //create a file in the /home/data/tasks.txt | ||
| File file = new File(path); | ||
| return file; | ||
| } | ||
|
|
||
| public void writeFile() { | ||
| FileClass fc = new FileClass(); | ||
| String filePath = HOME + "/data/stored.txt"; | ||
| fc.createFile(filePath); | ||
| for (int i = 0; i < taskArray.size(); i++) { | ||
| Task tasks = taskArray.get(i); | ||
| try { | ||
| String firstInitial = tasks.getInitial() ; //first initial character | ||
| String textToAdd = firstInitial + " | " + tasks.getStatusIcon() + " | " | ||
| + taskArray.get(i).getDescription(); | ||
| fc.writeFile(filePath, textToAdd); | ||
| } catch (IOException e) { | ||
| System.out.println("File is not found :(!"); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| public ArrayList<Task> getList() { | ||
| return this.taskArray; | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import java.util.ArrayList; | ||
|
|
||
| public class Task { | ||
| protected String description; | ||
| protected ArrayList<Boolean> isDone; | ||
|
|
||
| public Task(String description) { | ||
| this.description = description; | ||
| this.isDone = new ArrayList<Boolean>(); | ||
| isDone.add(false); | ||
| } | ||
|
|
||
| public String getStatusIcon() { | ||
| return (isDone.get(0) ? "[X]" : "[ ]"); // mark done task with X // if done is "X" then " " | ||
| } | ||
|
|
||
| public void setAsDone() { | ||
| isDone.set(0, true); | ||
| } | ||
|
|
||
| public void setAsUndone() { | ||
| isDone.set(0, false); | ||
| } | ||
|
|
||
| public String marking(String mark) { | ||
| if (mark.equals("mark")) { | ||
| setAsDone(); | ||
| String messageMarked = "Nice! I've marked this task as done: \n" + | ||
| this.toString() + "\n " | ||
| + "======================================="; | ||
| return messageMarked; | ||
| } else { | ||
| setAsUndone(); | ||
| String messageUnmarked = "OK, I've marked this task as not done yet: \n" + | ||
| this.toString() + "\n " | ||
| + "======================================="; | ||
| return messageUnmarked; | ||
|
|
||
| } | ||
| } | ||
|
|
||
| public String toString() { | ||
| return getStatusIcon() + " " + this.description; | ||
| } | ||
|
|
||
| public String getInitial(){ | ||
| return "Task"; | ||
| } | ||
|
|
||
| public String getDescription() { | ||
| return description; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps you could remove the indentation for the case clauses to follow the coding standards