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

[Goh Wei Kiat] iP #270

Open
wants to merge 65 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
3b19ba1
Add Gradle support
May 24, 2020
a75fcee
build.gradle: Update version to 8.29
Aug 29, 2020
7020044
Update Duke.java
mrweikiat Jan 18, 2021
8d73734
level2
mrweikiat Jan 18, 2021
fc455aa
level3
mrweikiat Jan 18, 2021
f286b75
level 4
mrweikiat Jan 19, 2021
238b224
level5
mrweikiat Jan 19, 2021
98bc1c3
level6
mrweikiat Jan 19, 2021
d1475b3
Update JAVADOCS comment
mrweikiat Jan 22, 2021
50e718d
Update Duke.java
mrweikiat Jan 22, 2021
3ba369a
A-TextUiTesting
mrweikiat Jan 22, 2021
4c53e33
Level 6
mrweikiat Jan 22, 2021
1e149a7
Update A-TextUiTesting
mrweikiat Jan 22, 2021
a1e2149
feature1
mrweikiat Jan 26, 2021
2348e76
Branch testing
mrweikiat Jan 26, 2021
2687090
Merge branch 'feature1'
mrweikiat Jan 26, 2021
9e92011
Level 7
mrweikiat Feb 2, 2021
67efef3
Level8
mrweikiat Feb 2, 2021
1eb74dd
A-MoreOOP
mrweikiat Feb 3, 2021
5a823a8
A-Packages
mrweikiat Feb 3, 2021
4f103fe
Level 9
mrweikiat Feb 3, 2021
ec6e328
Package Justin
mrweikiat Feb 6, 2021
3141a6a
A-JavaDoc
mrweikiat Feb 7, 2021
46a8cc9
Merge remote-tracking branch 'upstream/add-gradle-support'
mrweikiat Feb 7, 2021
6c45111
A-Gradle
mrweikiat Feb 7, 2021
bc42771
Level 10 GUI
mrweikiat Feb 8, 2021
6f08404
Added help taskbar
mrweikiat Feb 10, 2021
8207336
Add C-Extensions
mrweikiat Feb 10, 2021
5d0dca3
A-BetterGui
mrweikiat Feb 16, 2021
5e79d8a
Add Assertions
mrweikiat Feb 18, 2021
0e8119a
Improve Code Quality
mrweikiat Feb 18, 2021
c8d5d34
Add gradle.yml to workflow
mrweikiat Feb 18, 2021
4044436
Update Ui.png
mrweikiat Feb 18, 2021
9375e8b
Update README.md
mrweikiat Feb 18, 2021
1a76075
Update README.md
mrweikiat Feb 18, 2021
5d86cbf
Update README.md
mrweikiat Feb 18, 2021
ae164d8
Update README.md
mrweikiat Feb 18, 2021
6f07dc9
Improve on Ui
mrweikiat Feb 18, 2021
516ac7c
Merge branch 'master' of https://github.com/mrweikiat/ip
mrweikiat Feb 18, 2021
6d88cb0
Update README.md
mrweikiat Feb 18, 2021
ac112f7
Update README.md
mrweikiat Feb 18, 2021
ef5247a
Update README.md
mrweikiat Feb 18, 2021
c735e63
Update README.md
mrweikiat Feb 18, 2021
df6b25e
Update Ui.png
mrweikiat Feb 18, 2021
0fc6025
branch-A-CodeQuality
mrweikiat Feb 18, 2021
06271ce
branch-A-CodingStandard
mrweikiat Feb 18, 2021
3e9e0bd
Merge pull request #2 from mrweikiat/branch-A-CodeQuality
mrweikiat Feb 18, 2021
14fe879
branch-A-JavaDoc
mrweikiat Feb 18, 2021
5aabbc7
Merge pull request #3 from mrweikiat/branch-A-JavaDoc
mrweikiat Feb 18, 2021
3748d06
branch-A-Assertions
mrweikiat Feb 18, 2021
2ea782f
Merge pull request #4 from mrweikiat/branch-A-Assertions
mrweikiat Feb 18, 2021
d3135ad
branch-Level-10
mrweikiat Feb 18, 2021
3ae9e3e
Merge pull request #8 from mrweikiat/branch-Level-10
mrweikiat Feb 18, 2021
e03420c
Merge branch 'master' into branch-A-CodingStandard
mrweikiat Feb 18, 2021
c0ff7f4
Merge pull request #9 from mrweikiat/branch-A-CodingStandard
mrweikiat Feb 18, 2021
9f48c36
branch-Level-9
mrweikiat Feb 18, 2021
ef654c5
branch-Level-9
mrweikiat Feb 18, 2021
49007e1
Merge pull request #11 from mrweikiat/branch-Level-9
mrweikiat Feb 18, 2021
526d705
Update Code Quality
mrweikiat Feb 18, 2021
9659072
Merge branch 'master' of https://github.com/mrweikiat/ip
mrweikiat Feb 18, 2021
7e573ec
Add jar file
mrweikiat Feb 18, 2021
7ba0d2d
Update README.md
mrweikiat Feb 18, 2021
6cc0997
Update JavaDoc and Code Standard
mrweikiat Feb 18, 2021
081d1f8
Merge branch 'master' of https://github.com/mrweikiat/ip
mrweikiat Feb 18, 2021
4247723
Update README.md
mrweikiat Feb 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
4 changes: 4 additions & 0 deletions data/duke.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
E|1|catch dog|2019-12-10 18:00
D|0|catch mouse|2020-02-02
T|1|catch cat
1|catch eagle
3 changes: 3 additions & 0 deletions data/justin.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
D|0|catch dog|2021-02-03
1|catch cat
E|1|catch bird|2019-06-10 19:00
10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

19 changes: 19 additions & 0 deletions src/main/justin/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class Deadline extends Task {

protected String by;
protected LocalDate date;

public Deadline(String description, String by) {
super(description);
this.by = by;
this.date = LocalDate.parse(by);
}

@Override
public String toString() {
return "[D]" + super.toString() + " (by: " + date.format(DateTimeFormatter.ofPattern("MMM d yyyy")) + ")";
}
}
28 changes: 28 additions & 0 deletions src/main/justin/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.LocalTime;

public class Event extends Task {

protected String dateTime;
protected String date;
protected String time;
protected LocalDate date1;
protected LocalTime time1;

public Event(String description, String dateTime) {
super(description);
this.dateTime = dateTime;
String[] splits = dateTime.split("\\s+");
this.date = splits[0];
this.time = splits[1];
this.date1 = LocalDate.parse(date);
this.time1 = LocalTime.parse(time);
}

@Override
public String toString() {
return "[E]" + super.toString() + " (at: " + date1.format(DateTimeFormatter.ofPattern("MMM d yyyy")) + " " +

Choose a reason for hiding this comment

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

Might have exceeded line limit

time1.format(DateTimeFormatter.ofPattern("HH:mm")) + ")";
}
}
157 changes: 157 additions & 0 deletions src/main/justin/Justin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
import java.io.File;
import java.util.Scanner;

public class Justin {

private Storage storage;
private TaskList tasks;
private Ui ui;


public Justin(String filePath) {

ui = new Ui();
this.storage = new Storage(filePath);
tasks = storage.loadFile(filePath);

}

public void run() {

/*
* Justin is a chatbot that help users plan and organise tasks
* Justin stands for JUSt a TImetable(New) : JUSTIN
*
* Justin is able to create and manage new tasks
* 1) Mark tasks off as done
* 2) Set tasks as To Do's - <keyword> <name>
* 3) Set tasks as Deadline's - keyword : <keyword> <name> /by <day>
* 4) Set tasks as Event's - keyword : <keyword> <name> /at <day time>
* 5) Supports deletion of completed tasks with command delete <int>
*
* Justin also supports viewing the entire tasks list with the command list - keyword : <keyword>
* To end off the session user can input bye to terminate program - keyword : <keyword>
*
* @author Goh Wei Kiat aka github : mrweikiat
* @version CS2103T AY20/21 Semester 2, Individual Project 'IP'
*/


Scanner sc = new Scanner(System.in);

// Starting line for UI
ui.showWelcomeMessage();
ui.showHelpMessage();

// Condition for Duke to stop
boolean terminate = false;

Choose a reason for hiding this comment

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

Should this be canTerminate? Might be better to change to reflect boolean variable name


//Duke will keep repeating until command given "Bye"
while (!terminate) {

String text = sc.nextLine();

Parser pr = new Parser(text);

try {
String command = pr.checkCommand();

switch (command) {

case "BYE":

storage.saveFile(tasks, storage.getFilePath());
terminate = true; // terminates Duke
ui.showEndMessage();
break;

case "LIST":

ui.showListMessage();
ui.printList(tasks);
break;

case "DONE":

String num = text.substring(5); // take out the int value of the task to be completed
int listNum = Integer.parseInt(num); // changes to int
Task hold = tasks.getList().get(listNum - 1);
hold.markAsDone();
ui.showDoneMessage(tasks, listNum);
break;

case "DEADLINE":

String newText = text.substring(9); // remove deadline from the string text
// set delimiter to take out the description of the deadline
String description = newText.substring(0, newText.indexOf("/") - 1);
// set delimiter to take out date of the deadline
String date = newText.substring(newText.indexOf("/") + 4);

ui.printLine();
tasks.addDeadline(description, date);
ui.printLine();

break;

case "TODO":

String descriptionToDo = text.substring(text.indexOf(" ") + 1); // take out the item from the text
tasks.addToDo(descriptionToDo);

break;

case "EVENT":

String eventText = text.substring(text.indexOf(" ") + 1); // removing the event to get description
// set delimiter to obtain the description and the at
String descriptionEvent = eventText.substring(0, eventText.indexOf("/") - 1);
String dateEvent = eventText.substring(eventText.indexOf("/") + 4);
// splitting the date and time respectively
tasks.addEvent(descriptionEvent, dateEvent);

break;

case "DELETE":

String numDelete = text.substring(7); // take out the int value of the task to be completed
tasks.delete(numDelete);

break;

case "FIND": // for level 9

String findText = text.substring(text.indexOf(" ")+1); // key for searching
ui.printFoundTask(tasks.find(findText));

break;

default:

ui.printLine();
System.out.println("added: " + text);
ui.printLine();
// create new instance of task and add to the list
Task holder = new Task(text);
tasks.getList().add(holder); // position corresponds to item number

}
} catch (JustinException m) {
ui.printErrorMessage(m.getMessage());
}


}
sc.close();
}

public static void main(String[]args){

String userDir = System.getProperty("user.dir");
String filePath = userDir + File.separator + "data" + File.separator + "justin.txt";
new Justin(filePath).run();

}
}


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

private String fullText;

public Parser(String fullText) {
this.fullText = fullText;
}

public String checkCommand() throws JustinException {
try {

validate(fullText);

if (fullText.equals("bye")) {

return "BYE";

} else if (fullText.equals("list")) {

return "LIST";

} else if (fullText.contains("done")) {

return "DONE";

} else if (fullText.contains("deadline")) {

return "DEADLINE";

} else if (fullText.contains("todo")) {

return "TODO";

} else if (fullText.contains("event")) {

return "EVENT";

}
else if (fullText.contains("delete")) {

return "DELETE";

} else if (fullText.contains("find")) {

return "FIND";

}

else {

return "ADD";

}
} catch (JustinException m) {
throw new JustinException(m.getMessage());
}
}

static void validate(String text) throws JustinException {
if (text.length() < 5 && text.contains("todo") ) { // case 1
throw new JustinException("☹ OOPS!!! The description of a todo cannot be empty.");
}
else if (text.contains("blah")) { // case 2
throw new JustinException("☹ OOPS!!! I'm sorry, but I don't know what that means :-(");
} else if (text.length() < 10 && text.contains("deadline")) { // case 3
throw new JustinException("☹ OOPS!!! The description of a deadline cannot be empty.");
} else if (text.length() < 6 && text.contains("event")) { // case 4
throw new JustinException("☹ OOPS!!! The description of a event cannot be empty.");
}
}

}
Loading