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

[Tan Hong Liang] iP #501

Open
wants to merge 55 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
0d13617
Added Week 2 Level-1 Level-2 and Level-3
tanhl2000 Aug 28, 2022
e176f21
finished ToDo of Level-4 and cleaned up code
tanhl2000 Aug 28, 2022
ff600bd
Finished up Level-4, Event and Deadline task types added
tanhl2000 Aug 28, 2022
04c50e0
Level-5, did more cleanup of code
tanhl2000 Sep 2, 2022
cf80052
Level-6 done, ArrayList used from start, delete command implemented
tanhl2000 Sep 2, 2022
14fbfe9
Did small part of Level-9
tanhl2000 Sep 8, 2022
5442e79
Finished Level-7 with saving and loading done
tanhl2000 Sep 8, 2022
de18707
Level-8 done in parallel branch
tanhl2000 Sep 8, 2022
bd191ca
Merge tag 'Level-7'
tanhl2000 Sep 9, 2022
32a4edb
Merge tag 'Level-8'
tanhl2000 Sep 9, 2022
812a5f8
fix conflicts from merge
tanhl2000 Sep 9, 2022
d42fd1f
fixed merge errors and updated enums with strings
tanhl2000 Sep 9, 2022
cc19d6b
Level-A-MoreOOP, split into packages
tanhl2000 Sep 9, 2022
a3a39b8
Level-A-MoreOOP, fully split out the different packages and classes, …
tanhl2000 Sep 10, 2022
7408a38
Level-A-MoreOOP, fixed functionalities for non task producing commands
tanhl2000 Sep 10, 2022
c1cb522
Level-5, made a main exception class where all exceptions will extend…
tanhl2000 Sep 11, 2022
7718dc5
Level-A-MoreOOP and Level-Packages: Finished abtracting and implement…
tanhl2000 Sep 16, 2022
ba58ab6
Level-A-Gradle: Added gradle support and converted to Gradle project
tanhl2000 Sep 16, 2022
c85360a
Level-A-Gradle, fixed package and import declarations in all files.
tanhl2000 Sep 17, 2022
9e9dcd7
Level-A-JUnit: set up Junit, created 1 test file to test it out
tanhl2000 Sep 18, 2022
b248eee
Level-A-JUnitv2: Added Testing for TaskList
tanhl2000 Sep 18, 2022
1d8b29d
Level-A-Jar
tanhl2000 Sep 18, 2022
bde3039
Level-A-Javadoc: Added documentation for all classes except the tasks…
tanhl2000 Sep 18, 2022
174ec22
Level-A-CodingStandardsv1: Added comments for logical blocks, did a c…
tanhl2000 Sep 18, 2022
92b2745
Merge commit Level-9: Added find command
tanhl2000 Sep 18, 2022
76b923c
Merge tag 'Level-A-JavaDoc'
tanhl2000 Sep 18, 2022
632ab49
Merge commit: commit some untracked files, to ensure merge commited e…
tanhl2000 Sep 18, 2022
fc92a48
Merge branch 'Level-A-CodingStandards'
tanhl2000 Sep 18, 2022
fd15136
Level-7: updated saving and loading such that user may specify an add…
tanhl2000 Sep 19, 2022
c49356d
Level-10: Added JavaFX support and GUI, changed program flow to fit i…
tanhl2000 Sep 19, 2022
53c523e
Level-10: Added personalisation and cursory editing with FXML builder
tanhl2000 Sep 19, 2022
e2959fd
Level-10 and Level-Assertion: Finished Level-10 and added assertions
tanhl2000 Sep 19, 2022
13377a1
Merge commit Level-10: Merged Level-10 and Level-A-Assertions
tanhl2000 Sep 19, 2022
f48f75f
Level-10: fixed errors from previous merge deconflicting
tanhl2000 Sep 19, 2022
1ff9775
Level-A-Jar: Created jar file
tanhl2000 Sep 19, 2022
41ea42d
Level-10: added personalisation
tanhl2000 Sep 19, 2022
0957668
Level-A-CodeQuality: added more comprehensive javadocs, putting under…
tanhl2000 Sep 19, 2022
7c80298
Level-A-CodeQuality: changed most magic literals to constants
tanhl2000 Sep 19, 2022
0d7c9c1
Level-A-CodingQuality: added more comments in to improve readability
tanhl2000 Sep 19, 2022
21f3c2f
Merge pull request #2 from tanhl2000/Branch-Level-A-CodeQuality
tanhl2000 Sep 20, 2022
52c8f42
Level-C-Archive: Adding archive functionality, saving progress
tanhl2000 Sep 20, 2022
4e05947
Currently, users who want to save their current configuration of task…
tanhl2000 Sep 22, 2022
7963072
Update user guide
tanhl2000 Sep 22, 2022
636d061
General bug fixes and adding the Ui.png
tanhl2000 Sep 22, 2022
909bc1c
Merge the User guide
tanhl2000 Sep 22, 2022
c59219f
Bug fixes and improvements to code quality
tanhl2000 Sep 22, 2022
7d75648
Removed UI from storage as its never used
tanhl2000 Sep 22, 2022
0356d41
Final touches and adding clear archive functionality
tanhl2000 Sep 22, 2022
3a7811c
Update with clear command
tanhl2000 Sep 22, 2022
fe7c2af
Delete Ui.PNG
tanhl2000 Sep 23, 2022
ebf81e5
Add Ui.png
tanhl2000 Sep 23, 2022
b696e2a
Delete Ui.png.png
tanhl2000 Sep 23, 2022
02e1d24
Add files via upload
tanhl2000 Sep 23, 2022
63a9b27
Updated the UI background graphics opacity to be less distracting
tanhl2000 Sep 25, 2022
a01d243
Merge branch 'master' of https://github.com/tanhl2000/ip
tanhl2000 Sep 25, 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
9 changes: 9 additions & 0 deletions src/main/java/CommandType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
enum CommandType {
LIST,
MARK,
UNMARK,
TODO,
DEADLINE,
EVENT,
BYE
}
7 changes: 5 additions & 2 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ public class Deadline extends Task{

protected String dateTime;

public Deadline(String description, String dateTime) {
super(description);
public Deadline(String description, String dateTime) throws MissingArgumentException{
super("deadline", description, dateTime);
if (dateTime.equals("")) {
throw new MissingArgumentException("ERROR: deadline command requires a description.");
}
this.dateTime = dateTime;
}

Expand Down
151 changes: 99 additions & 52 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import java.util.Scanner;
import java.util.ArrayList;

public class Duke {
private static ArrayList<Task> tasks = new ArrayList<Task>();
Copy link

Choose a reason for hiding this comment

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

can consider making this a private static final variable

private static boolean isEnd = false;
Expand All @@ -19,70 +18,114 @@ public static void main(String[] args) {
String greeting = "Hello! I'm Duke \n" + "What can I do for you?\n";
Scanner userInput = new Scanner(System.in);
chat(greeting);
while (!isEnd) {
String userStatement = userInput.nextLine();
String splitUserStatement[] = userStatement.split(" ", 2);
String command = splitUserStatement[0];
String userArgs = "";
if (splitUserStatement.length > 1) {
userArgs = splitUserStatement[1];
while (!isEnd) {
try {
String[] parsedUserInput = parseCommand(userInput.nextLine());
String command = parsedUserInput[0];
String arg1 = parsedUserInput[1];
String arg2 = parsedUserInput[2];
switch(command) {
case COMMAND_LIST:
chat("Here are the tasks in your list: \n" + list());
break;
case COMMAND_BYE:
chat("Bye! Hope to see you again!\n");
isEnd = true;
userInput.close();
break;
case COMMAND_TODO:
if (arg1.equals("")) {
error("ToDo task requires a description");
break;
}
ToDo toDoToAdd = new ToDo(arg1);
tasks.add(toDoToAdd);
chat("Got it, I've added this task:\n " + toDoToAdd + "\n" + outputNumOfTasks());
break;
case COMMAND_DEADLINE:
Deadline deadlineToAdd = new Deadline(arg1, arg2);
tasks.add(deadlineToAdd);
chat("Got it, I've added this task:\n " + deadlineToAdd + "\n" + outputNumOfTasks());
break;
case COMMAND_EVENT:
Event eventToAdd = new Event(arg1, arg2);
tasks.add(eventToAdd);
chat("Got it, I've added this task:\n " + eventToAdd + "\n" + outputNumOfTasks());
break;
case COMMAND_MARK:
mark(Integer.parseInt(arg1));
break;
case COMMAND_UNMARK:
unmark(Integer.parseInt(arg1));
break;
default:
error("No or invalid command given, are you just looking to chat? :D");
break;
}
} catch (MissingArgumentException e) {
chat(e.getLocalizedMessage() + "\n");
} catch (InvalidCommandException e) {
chat(e.getLocalizedMessage() + "\n");
}
}
/*String[] splitUserArgs = userArgs.split("/by", 2);
String dateTime = "";
String description = splitUserArgs[0];
if (splitUserArgs.length > 1) {
dateTime = splitUserArgs[1];
} */
switch(command) {
}

public static String[] parseCommand(String userCommand) throws InvalidCommandException {
String[] parsedCommand = {"","",""};
String splitUserStatement[] = userCommand.split(" ", 2);
if (!isValidCommand(splitUserStatement[0])) {
throw new InvalidCommandException("Thats not an available command.");
}
String command = splitUserStatement[0];
parsedCommand[0] = command;
String userArgs = "";
if (splitUserStatement.length > 1) {
userArgs = splitUserStatement[1];
}
String[] splitUserArgs = {"",""};
if (command.equals(COMMAND_DEADLINE)) {
splitUserArgs = userArgs.split("/by", 2);
}
else if (command.equals(COMMAND_EVENT)) {
splitUserArgs = userArgs.split("/at", 2);
} else {
splitUserArgs = userArgs.split("/", 2);
}
parsedCommand[1] = splitUserArgs[0];
if (splitUserArgs.length > 1) {
parsedCommand[2] = splitUserArgs[1];
}
return parsedCommand;

}

public static boolean isValidCommand(String command) {
switch(command) { //no breaks as all cases lead to return
case COMMAND_LIST:
chat("Here are the tasks in your list: \n" + list());
break;
return true;
case COMMAND_BYE:
chat("Bye! Hope to see you again!\n");
isEnd = true;
break;
return true;
case COMMAND_TODO:
ToDo toDoToAdd = new ToDo(userArgs);
tasks.add(toDoToAdd);
chat("Got it, I've added this task:\n " + toDoToAdd + "\n" + outputNumOfTasks());
break;
case COMMAND_DEADLINE:
String[] splitUserArgs = userArgs.split("/by", 2);
String dateTime = "";
String description = splitUserArgs[0];
if (splitUserArgs.length > 1) {
dateTime = splitUserArgs[1];
}
Deadline deadlineToAdd = new Deadline(description, dateTime);
tasks.add(deadlineToAdd);
chat("Got it, I've added this task:\n " + deadlineToAdd + "\n" + outputNumOfTasks());
break;
case COMMAND_EVENT:
String[] splitUserArgs2 = userArgs.split("/at", 2);
String dateTime2 = "";
String description2 = splitUserArgs2[0];
if (splitUserArgs2.length > 1) {
dateTime2 = splitUserArgs2[1];
}
Event eventToAdd = new Event(description2, dateTime2);
tasks.add(eventToAdd);
chat("Got it, I've added this task:\n " + eventToAdd + "\n" + outputNumOfTasks());
break;
return true;
case COMMAND_DEADLINE:
return true;
case COMMAND_EVENT:
return true;
case COMMAND_MARK:
mark(Integer.parseInt(userArgs));
break;
return true;
case COMMAND_UNMARK:
unmark(Integer.parseInt(userArgs));
break;
return true;
default:
chat("Not a command, just wanna chat?");
return false;
}
}
}

public static String list() {
String output = "";
int count = 1;
if (tasks.size() == 0) {
return "No tasks! Yay!";
}
for (Task task : tasks) {
output += String.valueOf(count) + ". " + task + "\n";
count += 1;
Expand Down Expand Up @@ -111,6 +154,10 @@ public static void chat(String message) {
System.out.println(UI_LINE_SPACING + message + UI_LINE_SPACING);
}

public static void error(String message) {
System.out.println(UI_LINE_SPACING + ":( OOPS: " + message + "\n" + UI_LINE_SPACING);
}

public static void end() {
System.out.println(UI_LINE_SPACING + "Bye! Hope to see you again!" + UI_LINE_SPACING);
isEnd = true;
Copy link

Choose a reason for hiding this comment

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

Overall code is clear and the logic flows and should have no problem completing the IP

Expand Down
7 changes: 5 additions & 2 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ public class Event extends Task{

protected String duration;

public Event(String description, String duration) {
super(description);
public Event(String description, String duration) throws MissingArgumentException {
super("event", description, duration);
if (duration.equals("")) {
throw new MissingArgumentException("ERROR: event command is missing arguments.");
}
this.duration = duration;
}

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/InvalidCommandException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class InvalidCommandException extends Exception{

public InvalidCommandException(String message) {
super(message);
}
}
6 changes: 6 additions & 0 deletions src/main/java/MissingArgumentException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class MissingArgumentException extends Exception {

public MissingArgumentException(String message) {
super(message);
}
}
39 changes: 39 additions & 0 deletions src/main/java/Parser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
public class Parser {

private static final String COMMAND_LIST = "list";
private static final String COMMAND_BYE = "bye";
private static final String COMMAND_TODO = "todo";
private static final String COMMAND_DEADLINE = "deadline";
private static final String COMMAND_EVENT = "event";
private static final String COMMAND_MARK = "mark";
private static final String COMMAND_UNMARK = "unmark";

String type;
String description;
String dateTime;


public Parser(String userInput) throws InvalidCommandException {
String splitUserStatement[] = userInput.split(" ", 2);
String command = splitUserStatement[0];
switch (command) {

}
String userArgs = "";
if (splitUserStatement.length > 1) {
userArgs = splitUserStatement[1];
}
String[] splitUserArgs = userArgs.split("/by", 2);
String dateTime = "";
String description = splitUserArgs[0];
if (splitUserArgs.length > 1) {
dateTime = splitUserArgs[1];
}
}

public static void parseUserInput(String userInput) {

}


}
7 changes: 5 additions & 2 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
public class Task {
protected String type;
protected String description;
protected String dateTime;
protected boolean isDone;
Copy link

Choose a reason for hiding this comment

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

Seems that there is an extra white space followed by "protected" according to coding standard.

Copy link

Choose a reason for hiding this comment

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

Yes this violates the coding standard


Task (String description) {
this.description = description;
this.isDone = false;
}
Task (String description, boolean isDone) {
Task (String type, String description, String dateTime) {
this.description = description;
this.isDone = isDone;
this.dateTime = dateTime;
this.isDone = false;
}

public String getDescription() {
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/TaskType.java

This file was deleted.

10 changes: 10 additions & 0 deletions src/main/java/Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.InputMismatchException;
import java.util.Scanner;

public class Test {
public static void main(String[] args) {

}
}
21 changes: 15 additions & 6 deletions text-ui-test/EXPECTED.TXT
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
Hello from
____ _
| _ \ _ _| | _____
| | | | | | | |/ / _ \
| |_| | |_| | < __/
|____/ \__,_|_|\_\___|
----------------------------------------
Hello! I'm Duke
What can I do for you?
----------------------------------------

----------------------------------------
Got it, I've added this task:
[T][ ] work
Now you have 1 tasks in the list
----------------------------------------

----------------------------------------
Got it, I've added this task:
[D][ ] quiz (by: sunday)
Now you have 2 tasks in the list
----------------------------------------
2 changes: 2 additions & 0 deletions text-ui-test/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
todo work
deadline quiz /by sunday