-
Notifications
You must be signed in to change notification settings - Fork 454
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
[Quek Sze Long] iP #465
Open
szelongq
wants to merge
59
commits into
nus-cs2103-AY2122S1:master
Choose a base branch
from
szelongq: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
[Quek Sze Long] iP #465
Changes from 27 commits
Commits
Show all changes
59 commits
Select commit
Hold shift + click to select a range
d839859
Add Gradle support
ffbecea
Implement Duke Level 1
szelongq e72fa50
Implement Duke Level 2
szelongq f2d6f5c
Implement Duke Level 3
szelongq cf42835
Implement Duke Level-4
szelongq 7971be8
Implement Automated Text UI Testing
szelongq 6cb9d21
Implement Duke Level 5
szelongq 196ad71
Implement Duke Level 6
szelongq d86c5b7
Implement Enums for Task Types
szelongq 5e5d767
Fix Bugs from Level 6
szelongq a5ff454
Implement Duke Level 7
szelongq 1134b9e
Implement Duke Level 8
szelongq 07c8889
Merge branch 'branch-level-7'
szelongq 4fec8b9
Merge branch 'branch-Level-8'
szelongq d2844fe
Fix Bug from Merge with Level-7 and Level-8
szelongq f381098
Update Delete Feature to be work with Save Feature.
szelongq 9a6f675
Add Ui, Storage and LoadingException Classes
szelongq 091f13a
Implement Duke A-MoreOOP
szelongq 0cd6d66
Implement A-Packages
szelongq b827472
Implement Duke A-JUnit
szelongq 6c77dc9
Fix bug for when directory folder does not exist
szelongq ba8c40d
Implement Duke A-JavaDoc
szelongq 269836a
Implement Duke A-CodingStandard
szelongq 9473c7d
Implement Duke Level 9
szelongq 47bcbfe
Merge branch 'branch-A-JavaDoc'
szelongq e38c688
Merge branch 'branch-A-CodingStandard'
szelongq e2fa3b0
Merge branch 'branch-Level-9'
szelongq 113c0ba
Update Code as per Reviews.
szelongq 55aeb9d
Edit Code to Fit Coding Standard and Enhance Readability.
szelongq c1f35d1
Merge remote-tracking branch 'origin/add-gradle-support' into branch-…
szelongq 58690d1
Implement Duke A-Gradle
szelongq 9b353e5
Merge branch 'branch-A-Gradle'
szelongq a908b8d
Implement A-CheckStyle
szelongq d715bd1
Merge branch 'branch-A-CheckStyle'
szelongq f058d9d
Implement Duke Level 10
szelongq 2920388
Merge branch 'branch-Level-10'
szelongq 938b890
Fix bugs preventing JAR file generation.
szelongq f9939fc
Use Assertions
szelongq 046b9cf
Parser class: move parsing of TaskType to TaskType class
szelongq d03c6ee
Storage class: create a new method for parsing a saved task
szelongq 8b8c55c
Improve code readability
szelongq 51866b8
Merge pull request #1 from szelongq/branch-A-Assertions
szelongq e524958
Merge branch 'master' into branch-A-CodeQuality
szelongq 798da13
Merge pull request #2 from szelongq/branch-A-CodeQuality
szelongq 05a3a98
Create main.yml
szelongq 6c481ea
Add whitespaces to follow checkstyle format
szelongq f9c1232
Merge pull request #3 from szelongq/branch-A-CI
szelongq b3b4ba9
Add ability for the user to change the target save file
szelongq 8202463
Add javadoc comments
szelongq b912ebd
Merge pull request #4 from szelongq/branch-C-FlexibleDataSource
szelongq 98722d3
Improve GUI
szelongq c603d3c
Merge pull request #6 from szelongq/branch-A-BetterGui
szelongq aa78d57
Rebrand Duke as Tipsy
szelongq 2985e87
Fix Checkstyle Errors
szelongq b604602
Merge pull request #7 from szelongq/branch-Rebranding
szelongq df5cd71
Update README.md
szelongq d31778e
Add Product Screenshot
szelongq 2ccd941
Update User Guide
szelongq 803f2f8
Change to using gradle v6.2 instead of v6.3
szelongq 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 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 |
---|---|---|
|
@@ -15,3 +15,4 @@ bin/ | |
|
||
/text-ui-test/ACTUAL.txt | ||
text-ui-test/EXPECTED-UNIX.TXT | ||
data/duke.txt |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package duke; | ||
|
||
public enum CommandType { | ||
EXIT, LIST, ADD_TASK, COMPLETE_TASK, DELETE_TASK, FIND_TASK | ||
} |
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package duke; | ||
|
||
import java.time.LocalDate; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
public class Deadline extends Task{ | ||
private LocalDate taskDate; | ||
private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy"); | ||
|
||
public Deadline(String taskName, LocalDate taskDate, boolean isDone) { | ||
super(taskName, TaskType.DEADLINE, isDone); | ||
this.taskDate = taskDate; | ||
} | ||
|
||
public Deadline(String taskName, LocalDate taskDate) { | ||
this(taskName, taskDate, false); | ||
} | ||
|
||
@Override | ||
public String toSaveFormat() { | ||
return String.format("D, %d, %s, %s", isDone() ? 1 : 0, getTaskName(), taskDate); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("[D]%s (by: %s)", super.toString(), taskDate.format(formatter)); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package duke; | ||
|
||
import java.util.Scanner; | ||
|
||
public class Duke { | ||
|
||
private Ui ui; | ||
private Storage storage; | ||
private TaskList tasks; | ||
|
||
public Duke(String filepath) { | ||
ui = new Ui(); | ||
storage = new Storage(filepath); | ||
|
||
try { | ||
tasks = new TaskList(storage.load()); | ||
if (tasks.getSize() > 0) { | ||
ui.printLoadTasks(tasks); | ||
} | ||
} catch (DukeException e) { | ||
ui.printErrorMessage(e.getMessage()); | ||
tasks = new TaskList(); | ||
} | ||
} | ||
|
||
public void run() { | ||
ui.printStartInteractionsMessage(); | ||
|
||
Scanner scanner = new Scanner(System.in); | ||
String userInput; | ||
|
||
do { | ||
ui.printWaitingUserInput(); | ||
userInput = scanner.nextLine(); | ||
|
||
try { | ||
executeCommand(userInput); | ||
} catch (DukeException e) { | ||
ui.printErrorMessage(e.getMessage()); | ||
} | ||
// Duke will keep accepting user input until user inputs "bye", | ||
// which will lead to executeCommand() exiting the program. | ||
} while (true); | ||
szelongq marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
public static void main(String[] args) { | ||
new Duke("data/duke.txt").run(); | ||
} | ||
|
||
private void executeCommand(String userInput) throws DukeException { | ||
// First, extract the command type inputted by the user. | ||
// parseCommandType() will throw an UnsupportedOperationException if | ||
// no valid command types was inputted by the user. | ||
CommandType commandType = Parser.parseCommandType(userInput); | ||
|
||
// Decide the action to take depending on command type given. | ||
// parseNewTask() and parseTaskNum() will throw MissingInputException | ||
// if no valid further input is entered by the user. | ||
switch (commandType) { | ||
case EXIT: | ||
ui.printExitMessage(); | ||
System.exit(0); | ||
case LIST: | ||
ui.printTaskList(tasks); | ||
break; | ||
case ADD_TASK: | ||
addNewTask(Parser.parseNewTask(userInput)); | ||
break; | ||
case COMPLETE_TASK: | ||
completeTask(Parser.parseTaskNum(userInput)); | ||
break; | ||
case DELETE_TASK: | ||
deleteTask(Parser.parseTaskNum(userInput)); | ||
break; | ||
case FIND_TASK: | ||
findTask(Parser.parseSearchSubject(userInput)); | ||
break; | ||
} | ||
szelongq marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
private void addNewTask(Task newTask) { | ||
tasks.addTask(newTask); | ||
storage.saveTasks(tasks); | ||
ui.printAddTask(tasks, newTask); | ||
} | ||
|
||
private void completeTask(int taskNum) { | ||
tasks.completeTask(taskNum); | ||
storage.saveTasks(tasks); | ||
ui.printCompleteTask(tasks.getTask(taskNum)); | ||
} | ||
|
||
private void deleteTask(int taskNum) { | ||
Task deletedTask = tasks.deleteTask(taskNum); | ||
storage.saveTasks(tasks); | ||
ui.printDeleteTask(tasks, deletedTask); | ||
} | ||
|
||
private void findTask(String subject) { | ||
ui.printTasksWithSubject(tasks, subject); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package duke; | ||
|
||
/** | ||
* DukeException is the class that represents exceptions in the | ||
* logic of the script components in Duke. | ||
*/ | ||
public class DukeException extends Exception { | ||
/** | ||
* Class constructor. | ||
* | ||
* @param message the message describing the error that occurred. | ||
*/ | ||
public DukeException(String message) { | ||
super(message); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package duke; | ||
|
||
import java.time.LocalDate; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
public class Event extends Task { | ||
private LocalDate taskDate; | ||
private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd LLLL yyyy"); | ||
|
||
public Event(String taskName, LocalDate taskDate, boolean isDone) { | ||
super(taskName, TaskType.EVENT, isDone); | ||
this.taskDate = taskDate; | ||
} | ||
|
||
public Event(String taskName, LocalDate taskDate) { | ||
this(taskName, taskDate, false); | ||
} | ||
|
||
@Override | ||
public String toSaveFormat() { | ||
return String.format("E, %d, %s, %s", isDone() ? 1 : 0, getTaskName(), taskDate); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("[E]%s (at: %s)", super.toString(), taskDate.format(formatter)); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package duke; | ||
|
||
public class LoadingException extends DukeException{ | ||
public LoadingException() { | ||
super("An error with loading has occurred"); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package duke; | ||
|
||
public class MissingInputException extends DukeException { | ||
public MissingInputException(TaskType taskType) { | ||
super("The description for " + taskType + " cannot be empty"); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package duke; | ||
|
||
import java.time.LocalDate; | ||
import java.util.Scanner; | ||
|
||
/** | ||
* Parser is the class that deals with making sense of the user commands. | ||
*/ | ||
public class Parser { | ||
|
||
/** | ||
* Returns type of command given in the specified user input. | ||
* | ||
* @param userInput the whole line of command from the user. | ||
* @return the type of command requested. | ||
* @throws UnsupportedOperationException if the user entered a | ||
* command that is not recognized. | ||
*/ | ||
public static CommandType parseCommandType(String userInput) | ||
throws UnsupportedOperationException { | ||
|
||
Scanner userInputScanner = new Scanner(userInput); | ||
String operation = userInputScanner.next(); | ||
|
||
switch (operation.toLowerCase()) { | ||
case "bye": | ||
return CommandType.EXIT; | ||
case "list": | ||
return CommandType.LIST; | ||
case "done": | ||
return CommandType.COMPLETE_TASK; | ||
case "todo": | ||
// Fallthrough | ||
case "deadline": | ||
// Fallthrough | ||
case "event": | ||
return CommandType.ADD_TASK; | ||
case "delete": | ||
return CommandType.DELETE_TASK; | ||
case "find": | ||
return CommandType.FIND_TASK; | ||
default: | ||
throw new UnsupportedOperationException(); | ||
} | ||
} | ||
|
||
/** | ||
* Creates a new task based on the user's inputs. | ||
* The user command given is expected to be "todo", "deadline" | ||
* or "event". | ||
* | ||
* @param userInput the whole line of command from the user. | ||
* @return the new task that was requested. | ||
* @throws MissingInputException if the user did not enter any | ||
* other task details after the command word. | ||
*/ | ||
public static Task parseNewTask(String userInput) throws MissingInputException { | ||
Scanner userInputScanner = new Scanner((userInput)); | ||
TaskType taskType = null; | ||
switch (userInputScanner.next().toLowerCase()) { | ||
case "todo": | ||
taskType = TaskType.TODO; | ||
break; | ||
case "deadline": | ||
taskType = TaskType.DEADLINE; | ||
break; | ||
case "event": | ||
taskType = TaskType.EVENT; | ||
break; | ||
default: | ||
return null; // Invalid input | ||
} | ||
szelongq marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (!userInputScanner.hasNext()) { | ||
throw new MissingInputException(taskType); | ||
} | ||
|
||
switch (taskType) { | ||
case TODO: | ||
return new ToDo(userInputScanner.nextLine().trim()); | ||
case DEADLINE: | ||
userInputScanner.useDelimiter(" /by "); | ||
return new Deadline(userInputScanner.next().trim(), | ||
LocalDate.parse(userInputScanner.next().trim())); | ||
case EVENT: | ||
userInputScanner.useDelimiter(" /at "); | ||
return new Event(userInputScanner.next().trim(), | ||
LocalDate.parse(userInputScanner.next().trim())); | ||
default: | ||
return null; // Error | ||
} | ||
} | ||
|
||
/** | ||
* Returns the task number specified in the user command. | ||
* The user command given is expected to be "done" or "delete". | ||
* | ||
* @param userInput the whole line of command from the user. | ||
* @return the number of the task to execute the command on. | ||
*/ | ||
public static int parseTaskNum(String userInput) { | ||
Scanner userInputScanner = new Scanner(userInput); | ||
userInputScanner.next(); | ||
return userInputScanner.nextInt(); | ||
} | ||
|
||
public static String parseSearchSubject(String userInput) { | ||
Scanner userInputScanner = new Scanner(userInput); | ||
userInputScanner.next(); | ||
return userInputScanner.nextLine().trim(); | ||
} | ||
} |
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.
I like your use of enums for this case!