Skip to content
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
wants to merge 59 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
d839859
Add Gradle support
May 24, 2020
ffbecea
Implement Duke Level 1
szelongq Aug 18, 2021
e72fa50
Implement Duke Level 2
szelongq Aug 18, 2021
f2d6f5c
Implement Duke Level 3
szelongq Aug 18, 2021
cf42835
Implement Duke Level-4
szelongq Aug 18, 2021
7971be8
Implement Automated Text UI Testing
szelongq Aug 18, 2021
6cb9d21
Implement Duke Level 5
szelongq Aug 18, 2021
196ad71
Implement Duke Level 6
szelongq Aug 18, 2021
d86c5b7
Implement Enums for Task Types
szelongq Aug 18, 2021
5e5d767
Fix Bugs from Level 6
szelongq Aug 26, 2021
a5ff454
Implement Duke Level 7
szelongq Aug 26, 2021
1134b9e
Implement Duke Level 8
szelongq Aug 26, 2021
07c8889
Merge branch 'branch-level-7'
szelongq Aug 26, 2021
4fec8b9
Merge branch 'branch-Level-8'
szelongq Aug 26, 2021
d2844fe
Fix Bug from Merge with Level-7 and Level-8
szelongq Aug 26, 2021
f381098
Update Delete Feature to be work with Save Feature.
szelongq Aug 26, 2021
9a6f675
Add Ui, Storage and LoadingException Classes
szelongq Aug 26, 2021
091f13a
Implement Duke A-MoreOOP
szelongq Aug 26, 2021
0cd6d66
Implement A-Packages
szelongq Aug 26, 2021
b827472
Implement Duke A-JUnit
szelongq Aug 26, 2021
6c77dc9
Fix bug for when directory folder does not exist
szelongq Aug 26, 2021
ba8c40d
Implement Duke A-JavaDoc
szelongq Aug 27, 2021
269836a
Implement Duke A-CodingStandard
szelongq Aug 28, 2021
9473c7d
Implement Duke Level 9
szelongq Aug 28, 2021
47bcbfe
Merge branch 'branch-A-JavaDoc'
szelongq Aug 28, 2021
e38c688
Merge branch 'branch-A-CodingStandard'
szelongq Aug 28, 2021
e2fa3b0
Merge branch 'branch-Level-9'
szelongq Aug 28, 2021
113c0ba
Update Code as per Reviews.
szelongq Aug 31, 2021
55aeb9d
Edit Code to Fit Coding Standard and Enhance Readability.
szelongq Sep 1, 2021
c1f35d1
Merge remote-tracking branch 'origin/add-gradle-support' into branch-…
szelongq Sep 1, 2021
58690d1
Implement Duke A-Gradle
szelongq Sep 1, 2021
9b353e5
Merge branch 'branch-A-Gradle'
szelongq Sep 1, 2021
a908b8d
Implement A-CheckStyle
szelongq Sep 1, 2021
d715bd1
Merge branch 'branch-A-CheckStyle'
szelongq Sep 1, 2021
f058d9d
Implement Duke Level 10
szelongq Sep 2, 2021
2920388
Merge branch 'branch-Level-10'
szelongq Sep 2, 2021
938b890
Fix bugs preventing JAR file generation.
szelongq Sep 8, 2021
f9939fc
Use Assertions
szelongq Sep 8, 2021
046b9cf
Parser class: move parsing of TaskType to TaskType class
szelongq Sep 8, 2021
d03c6ee
Storage class: create a new method for parsing a saved task
szelongq Sep 8, 2021
8b8c55c
Improve code readability
szelongq Sep 8, 2021
51866b8
Merge pull request #1 from szelongq/branch-A-Assertions
szelongq Sep 8, 2021
e524958
Merge branch 'master' into branch-A-CodeQuality
szelongq Sep 8, 2021
798da13
Merge pull request #2 from szelongq/branch-A-CodeQuality
szelongq Sep 8, 2021
05a3a98
Create main.yml
szelongq Sep 9, 2021
6c481ea
Add whitespaces to follow checkstyle format
szelongq Sep 9, 2021
f9c1232
Merge pull request #3 from szelongq/branch-A-CI
szelongq Sep 9, 2021
b3b4ba9
Add ability for the user to change the target save file
szelongq Sep 9, 2021
8202463
Add javadoc comments
szelongq Sep 9, 2021
b912ebd
Merge pull request #4 from szelongq/branch-C-FlexibleDataSource
szelongq Sep 9, 2021
98722d3
Improve GUI
szelongq Sep 17, 2021
c603d3c
Merge pull request #6 from szelongq/branch-A-BetterGui
szelongq Sep 17, 2021
aa78d57
Rebrand Duke as Tipsy
szelongq Sep 17, 2021
2985e87
Fix Checkstyle Errors
szelongq Sep 17, 2021
b604602
Merge pull request #7 from szelongq/branch-Rebranding
szelongq Sep 17, 2021
df5cd71
Update README.md
szelongq Sep 17, 2021
d31778e
Add Product Screenshot
szelongq Sep 18, 2021
2ccd941
Update User Guide
szelongq Sep 18, 2021
803f2f8
Change to using gradle v6.2 instead of v6.3
szelongq Sep 18, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ bin/

/text-ui-test/ACTUAL.txt
text-ui-test/EXPECTED-UNIX.TXT
data/duke.txt
10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

5 changes: 5 additions & 0 deletions src/main/java/duke/CommandType.java
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
Copy link

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!

}
28 changes: 28 additions & 0 deletions src/main/java/duke/Deadline.java
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));
}
}
102 changes: 102 additions & 0 deletions src/main/java/duke/Duke.java
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);
}
}
16 changes: 16 additions & 0 deletions src/main/java/duke/DukeException.java
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);
}
}
28 changes: 28 additions & 0 deletions src/main/java/duke/Event.java
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));
}
}
7 changes: 7 additions & 0 deletions src/main/java/duke/LoadingException.java
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");
}
}
7 changes: 7 additions & 0 deletions src/main/java/duke/MissingInputException.java
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");
}
}
112 changes: 112 additions & 0 deletions src/main/java/duke/Parser.java
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();
}
}
Loading