Skip to content
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d839859
Add Gradle support
May 24, 2020
f793428
Level-1
tomascherian Jan 20, 2022
a2a56a0
Add Task.java
tomascherian Jan 23, 2022
cd380db
Remove Duke
tomascherian Jan 23, 2022
137a3e6
Update Pac and Task.
tomascherian Jan 24, 2022
850f362
Add Event ToDo and Deadline. Update Keyword and Pac.
tomascherian Jan 25, 2022
3f1737f
Add Expected.txt and Input.txt
tomascherian Jan 26, 2022
b0d9915
Handle Exceptions in Pac.java. Add PacException.java
tomascherian Jan 26, 2022
57b362b
Add delete to Pac.java
tomascherian Jan 26, 2022
566e815
Update Pac.java
tomascherian Mar 1, 2022
ee770fd
Update Pac.java
tomascherian Mar 1, 2022
c30f64c
Update Pac.java, Deadline.java, Event.java
tomascherian Mar 1, 2022
f3ca7bb
Merge branch 'branch-Level-8'
tomascherian Mar 1, 2022
2b56999
Merge branch 'branch-Level-7'
tomascherian Mar 1, 2022
22bf473
Refactor code to make it more OOP
tomascherian Mar 19, 2022
d95d9ba
Divide classes to packages
tomascherian Mar 19, 2022
5b61b13
Modify Mark and Unmark
tomascherian Mar 20, 2022
dc3a89e
Modify Task to run tests
tomascherian Mar 20, 2022
d71f0d8
Add JUnit tests
tomascherian Mar 20, 2022
0e3967d
Create jar file
tomascherian Mar 20, 2022
7b3dca2
Add find feature
tomascherian Mar 20, 2022
77c95e0
Merge remote-tracking branch 'origin/add-gradle-support'
tomascherian Mar 20, 2022
abb74db
Update build.gradle
tomascherian Mar 20, 2022
f15a3db
Add GUI
tomascherian Mar 20, 2022
91c7ff3
Add Snooze/Reschedule feature
tomascherian Mar 20, 2022
9458bc3
Update User Guide.
tomascherian Mar 21, 2022
065efba
Add JavaDoc comments
tomascherian Mar 21, 2022
0224d85
Add UI.png
tomascherian Mar 21, 2022
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
17 changes: 17 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
public class Deadline extends Task{
private final String dateTime;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Var declares as final may need to be in all capital letters, eg: DATE_TIME


String getDateTime() {
return dateTime;
}

Deadline(String description, String dateTime) {
super(description);
this.dateTime = dateTime;
}

@Override
public String toString() {
return "[D]" + super.toString() + "(by: " + getDateTime() + ")";
}
}
10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

17 changes: 17 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
public class Event extends Task {
private final String dateTime;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final var too 😄


String getDateTime() {
return dateTime;
}

Event(String description, String dateTime) {
super(description);
this.dateTime = dateTime;
}

@Override
public String toString() {
return "[E]" + super.toString() + "(at: " + getDateTime() + ")";
}
}
11 changes: 11 additions & 0 deletions src/main/java/Keyword.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public enum Keyword {
LIST,
MARK,
UNMARK,
TODO,
DEADLINE,
EVENT,
DELETE,
BYE,
ERROR
}
229 changes: 229 additions & 0 deletions src/main/java/Pac.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
import java.util.Scanner;
import java.util.ArrayList;

public class Pac {
static String logo = " ____ ___ _____\n"
+ "| _ \\ / _ \\ | ___|\n"
+ "| |_| | | |_| | | |\n"
+ "| __/ | | | | | |___\n"
+ "|_| |_| |_| |_____|\n";
static String newline = "----------------------------------------------------";
Copy link
Copy Markdown

@manu2002g manu2002g Feb 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the logo and newline variables be made final? And their names changed to fit the coding standard for naming constants eg: LOGO

static ArrayList<Task> tasks = new ArrayList<>();

public static void main(String[] args) {

System.out.println("\n" + newline + "\n" + newline + "\n" + logo);
System.out.println("Hello there! I'm Pac, your very own Personal Assistant ChatBot.\nHow may I help you?");
System.out.println(newline + "\n");

Scanner sc = new Scanner(System.in);

while (true) {
String input = sc.nextLine();
try {
String[] inputArray = input.split(" ", 2);
String firstword = inputArray[0].toLowerCase();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name as firstWord maybe better

Keyword keyword;

switch (firstword) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The coding standard says that we shouldn't indent the case statements under switch I think it's possible to configure IntelliJ to follow this by default.

case "bye":
keyword = Keyword.BYE;
break;
case "list":
keyword = Keyword.LIST;
break;
case "mark":
keyword = Keyword.MARK;
break;
case "unmark":
keyword = Keyword.UNMARK;
break;
case "todo":
keyword = Keyword.TODO;
break;
case "deadline":
keyword = Keyword.DEADLINE;
break;
case "event":
keyword = Keyword.EVENT;
break;
case "delete":
keyword = Keyword.DELETE;
break;
default:
keyword = Keyword.ERROR;
break;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can consider using a hashmap to lookup the right Keyword given a string? same functionality but may save some lines, may look slightly more readable as well, but it's up to you


switch (keyword) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The case statements here should also not be intended

case BYE:
exitPac();
break;
case LIST:
displayList();
break;
case MARK:
if (inputArray.length == 1) {
throw new PacException("MARK should be followed by a integer.");
}
try {
markTask(Integer.parseInt(inputArray[1]) - 1);
} catch (NumberFormatException e) {
System.out.println(newline + "\nSorry! MARK should be followed by a integer.\n"
+ newline + "\n");
} catch (IndexOutOfBoundsException e) {
System.out.println(newline + "\nSorry! Please mention a valid task number.\n"
+ newline + "\n");
}
break;
case UNMARK:
if (inputArray.length == 1) {
throw new PacException("UNMARK should be followed by a integer.");
}
try {
unmarkTask(Integer.parseInt(inputArray[1]) - 1);
} catch (NumberFormatException e) {
System.out.println(newline + "\nSorry! MARK should be followed by a integer.\n"
+ newline + "\n");
} catch (IndexOutOfBoundsException e) {
System.out.println(newline + "\nSorry! Please mention a valid task number.\n"
+ newline + "\n");
}
break;
case TODO:
if (inputArray.length == 1) {
throw new PacException("Please mention a task.");
}
addToDo(inputArray[1]);
break;
case DEADLINE:
if (inputArray.length == 1) {
throw new PacException("Please mention a task.");
}
try {
addDeadline(inputArray[1]);
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println(newline + "\nSorry! Command format is incorrect.\n"
+ newline + "\n");
}
break;
case EVENT:
if (inputArray.length == 1) {
throw new PacException("Please mention a task.");
}
try {
addEvent(inputArray[1]);
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println(newline + "\nSorry! Command format is incorrect.\n"
+ newline + "\n");
}
break;
case DELETE:
if (inputArray.length == 1) {
throw new PacException("DELETE should be followed by a integer.");
}
try {
deleteTask(Integer.parseInt(inputArray[1]) - 1);
} catch (NumberFormatException e) {
System.out.println(newline + "\nSorry! MARK should be followed by a integer.\n"
+ newline + "\n");
} catch (IndexOutOfBoundsException e) {
System.out.println(newline + "\nSorry! Please mention a valid task number.\n"
+ newline + "\n");
}
break;
case ERROR:
throw new PacException("I don't know what this means");
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can consider rewriting these lines of code into separate functions to avoid deep nesting

} catch (PacException e) {
System.out.println(newline + "\n" + e.getMessage() + "\n" + newline + "\n");
}
}
}

public static void addToDo(String description) {
try {
if (description.isBlank()) {
throw new PacException("Please mention a task.");
}
Task task = new ToDo(description);
tasks.add(task);
System.out.println(newline + "\nadded: " + task.toString());
System.out.println("You have " + tasks.size() + " tasks in your list" + "\n" + newline + "\n");
} catch (PacException e) {
System.out.println(newline + "\n" + e.getMessage() + "\n" + newline + "\n");
}
}

public static void addDeadline(String input) {
try {
String[] inputArray = input.split("/");
inputArray[1] = inputArray[1].replaceFirst("BY ", "by ");
inputArray[1] = inputArray[1].replaceFirst("By ", "by ");
inputArray[1] = inputArray[1].replaceFirst("bY ", "by ");
inputArray[1] = inputArray[1].split("by ", 2)[1];
if (inputArray[1].isBlank()) {
throw new PacException("Please enter a valid date or time.");
}
Task task = new Deadline(inputArray[0], inputArray[1]);
tasks.add(task);
System.out.println(newline + "\nadded: " + task.toString());
System.out.println("You have " + tasks.size() + " tasks in your list" + "\n" + newline + "\n");
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you can add a few blank lines in this code block to make it more readable? The coding standard suggest that "Logical units within a block should be separated by one blank line." Perhaps you could add blank lines to separate the code into sections dealing with formatting, processing and output.

} catch (PacException e) {
System.out.println(newline + "\n" + e.getMessage() + "\n" + newline + "\n");
}
}

public static void addEvent(String input) {
try {
String[] inputArray = input.split("/");
inputArray[1] = inputArray[1].replaceFirst("AT ", "by ");
inputArray[1] = inputArray[1].replaceFirst("At ", "by ");
inputArray[1] = inputArray[1].replaceFirst("aT ", "by ");
inputArray[1] = inputArray[1].split("at ", 2)[1];
if (inputArray[1].isBlank()) {
throw new PacException("Please enter a valid date or time.");
}
Task task = new Event(inputArray[0], inputArray[1]);
tasks.add(task);
System.out.println(newline + "\nadded: " + task.toString());
System.out.println("You have " + tasks.size() + " tasks in your list" + "\n" + newline + "\n");
} catch (PacException e) {
System.out.println(newline + "\n" + e.getMessage() + "\n" + newline + "\n");
}
}

public static void markTask(int index) {
tasks.get(index).markAsDone();
System.out.println(newline);
System.out.println("Task is marked as done. \n" + tasks.get(index));
System.out.println(newline + "\n");
}

public static void unmarkTask(int index) {
tasks.get(index).markAsNotDone();
System.out.println(newline);
System.out.println("Task is marked as not done. \n" + tasks.get(index));
System.out.println(newline + "\n");
}

public static void deleteTask(int index) {
System.out.println(newline + "\nTask has been deleted: " + tasks.get(index));
tasks.remove(index);
System.out.println("You have " + tasks.size() + " tasks in your list" + "\n" + newline + "\n");
}

public static void displayList() {
int i = 1;
System.out.println(newline);
for (Task task : tasks) {
System.out.println(i++ +". " + task);;
}
System.out.println(newline + "\n");
}

public static void exitPac() {
System.out.println(newline + "\n" + "Goodbye! See you soon. :)\n" + newline);
System.exit(0);
}
}
10 changes: 10 additions & 0 deletions src/main/java/PacException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
public class PacException extends Exception{
PacException(String message) {
super(message);
}

@Override
public String getMessage() {
return "Sorry! " + super.getMessage();
}
}
32 changes: 32 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
public class Task {
private final String description;
private boolean isDone;

Task(String description) {
this.description = description;
this.isDone = false;
}

boolean markAsDone() {
this.isDone = true;
return this.isDone;
}

boolean markAsNotDone() {
this.isDone = false;
return this.isDone;
}

String getDescription() {
return this.description;
}

@Override
public String toString() {
if (this.isDone) {
return "[X] " + this.description;
} else {
return "[ ] " + this.description;
}
}
}
10 changes: 10 additions & 0 deletions src/main/java/ToDo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
public class ToDo extends Task {
ToDo(String description) {
super(description);
}

@Override
public String toString() {
return "[T]" + super.toString();
}
}
Loading