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

[Rushagrid] Duke Increments #536

Open
wants to merge 47 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
65f72a8
Add support for Gradle workflow
j-lum Aug 6, 2019
0112efe
Add sample checkstyle configuration
j-lum Aug 12, 2019
cfd6da7
Change file mode on `gradle` to be executable
j-lum Aug 18, 2019
6e6ace1
Merge pull request #12 from j-lum/gradle+x
j-lum Aug 18, 2019
fbc2e85
Commit level1
Krit-K Aug 21, 2019
ca73428
Finish level-2
Krit-K Aug 22, 2019
84d245e
added Task and complete level-3
Krit-K Aug 22, 2019
c15dfc1
finish level 4
Krit-K Aug 22, 2019
411be71
added handling exceptions
Krit-K Aug 22, 2019
7209013
added delete function
Krit-K Aug 22, 2019
102862a
Finish Level-7
Krit-K Aug 29, 2019
f9f3527
Finish level-8
Krit-K Aug 29, 2019
43ff40f
Merge branch 'branch-Level-7'
Krit-K Aug 29, 2019
bbe2e9f
MoreOOP
Krit-K Aug 29, 2019
f1e79b8
A-JUnit
Krit-K Aug 29, 2019
6513b38
added Java Doc
Krit-K Aug 30, 2019
28e6bd1
Adhering to coding standards on all classes
Krit-K Aug 30, 2019
dbd9c3b
Added find function
Krit-K Aug 30, 2019
68e595a
Merge branch 'branch-A-JavaDoc' into branch-Level-9
Krit-K Sep 5, 2019
0c3790e
Merge branch 'branch-A-CodingStandard' into branch-Level-9
Krit-K Sep 5, 2019
f4bf590
fixed find function
Krit-K Sep 5, 2019
aa4775d
Merge branch 'gradle' of https://github.com/ArgVampir/duke
Krit-K Sep 5, 2019
a25e476
added gradle wrapper
Krit-K Sep 5, 2019
f7938fd
added test function
Krit-K Sep 5, 2019
421396a
finish level-10
Krit-K Sep 5, 2019
c6fac47
Add java docs and tidy up code
Krit-K Sep 12, 2019
ce5794e
added assertions
Krit-K Sep 12, 2019
f95aaac
Revert "added assertions"
Krit-K Sep 12, 2019
4dabcff
added event Sort function
Krit-K Sep 13, 2019
c719497
fixed minor bugs
Krit-K Sep 13, 2019
f6cace4
Added function and resolve bugs
Krit-K Sep 17, 2019
bbab4b8
added comments in assert
Krit-K Sep 17, 2019
71f02b7
Fix date and time issue
Krit-K Sep 19, 2019
7d9593c
Added all sort function for todo deadline and event. Fixed bugs with …
Krit-K Sep 19, 2019
e607727
Make the code more private and break down the Storage for cleaner code
Krit-K Sep 19, 2019
1af3b5f
Merge branch 'branch-A-Assertions'
Krit-K Sep 19, 2019
f2fc750
Merge branch 'branch-A-CodeQuality'
Krit-K Sep 19, 2019
99ed924
Merge branch 'branch-C-Sort'
Krit-K Sep 19, 2019
f75def9
Set theme jekyll-theme-architect
Krit-K Sep 30, 2019
5f630e2
Added a theme to the program and userguide
Krit-K Sep 30, 2019
9576a13
Merge branch 'master' of https://github.com/ArgVampir/duke
Krit-K Sep 30, 2019
f181298
indentation
Krit-K Sep 30, 2019
2b80f7a
added image
Krit-K Sep 30, 2019
8c6da0d
Adhere to coding style, add check file exist in storage, minor fixes …
Krit-K Sep 30, 2019
923b831
change slight layout on readme
Krit-K Sep 30, 2019
7ffa124
chang name
Krit-K Sep 30, 2019
e61a9d2
changed back to Ui.png
Krit-K Sep 30, 2019
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
6 changes: 3 additions & 3 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import java.util.Date;

public class Deadline extends Task {
protected Date by;
private Date by;

public Deadline(String description, Date by) {
Deadline(String description, Date by) {
super(description);
this.by = by;
}

public Date getBy() {
Date getBy() {
return this.by;
}

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import java.io.FileNotFoundException;
import java.text.ParseException;

/**
Expand All @@ -15,7 +14,7 @@ public class Duke {
* Initializes the Duke application and the storage file.
*/

Duke() throws FileNotFoundException {
Duke() {
ui = new Ui();
Storage storage = new Storage("../duke.txt");
taskList = new TaskList(Storage.load());
Expand Down
80 changes: 44 additions & 36 deletions src/main/java/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Deals with loading tasks from the file and saving tasks in the file
*/

public class Storage {
class Storage {

private static File file;

Expand All @@ -26,56 +26,64 @@ public class Storage {
* @return taskList
*/

static ArrayList<Task> load() throws FileNotFoundException {

static ArrayList<Task> load() {
ArrayList<Task> taskList = new ArrayList<>();
try {
Scanner sc = new Scanner(file);
while (sc.hasNext()) {

String[] task = sc.nextLine().split("\\|");
String taskType = task[0].trim();
boolean isTaskDone = task[2].trim().equals("1");

switch (taskType) {
case "T":
Todo newTask = new Todo(task[2].trim());
if (isTaskDone) newTask.markAsDone();
taskList.add(newTask);
break;
case "E":
String eventDescription = task[2].trim();
String at = task[3].trim();
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HHmm");
Event newEvent = new Event(eventDescription, sdf.parse(at));
if (isTaskDone) newEvent.markAsDone();
taskList.add(newEvent);
break;
case "D":
String deadlineDescription = task[2].trim();
String by = task[3].trim();
SimpleDateFormat sdf2 = new SimpleDateFormat("dd/MM/yyyy HHmm");
Deadline newDeadline = new Deadline(deadlineDescription, sdf2.parse(by));
if (isTaskDone) newDeadline.markAsDone();
taskList.add(newDeadline);
break;
default:
updateData(taskList, task);
Copy link

Choose a reason for hiding this comment

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

it was a great idea to abstract out this long chunk :)

}
}
} catch (FileNotFoundException | ParseException err) {
System.out.println(err.getMessage());
} catch (FileNotFoundException | ParseException e) {
System.out.println(e.getMessage());
}
return taskList;
}

/**
* Saves the current taskList onto the hard drive
* Update the taskList that will later be loaded
*
* @param taskList
* @param taskList The record of tasks to be updated
* @param task An array split into sections within the task
*/

private static void updateData(ArrayList<Task> taskList, String[] task) throws ParseException {
String taskType = task[0].trim();
boolean isTaskDone = task[1].trim().equals("1");

switch (taskType) {
case "T":
Todo newTask = new Todo(task[2].trim());
if (isTaskDone) newTask.markAsDone();
taskList.add(newTask);
break;
case "E":
String eventDescription = task[2].trim();
String at = task[3].trim();
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HHmm");
Event newEvent = new Event(eventDescription, sdf.parse(at));
if (isTaskDone) newEvent.markAsDone();
taskList.add(newEvent);
break;
case "D":
String deadlineDescription = task[2].trim();
String by = task[3].trim();
SimpleDateFormat sdf2 = new SimpleDateFormat("dd/MM/yyyy HHmm");
Deadline newDeadline = new Deadline(deadlineDescription, sdf2.parse(by));
if (isTaskDone) newDeadline.markAsDone();
taskList.add(newDeadline);
break;
default:
}
}

/**
* Saves the current taskList onto the hard drive
*
* @param taskList The record of tasks to be saved
*/

public static void saveTaskList(List<Task> taskList) {
static void saveTaskList(List<Task> taskList) {
try {
FileWriter fw = new FileWriter(file);
for (Task task : taskList) {
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
public class Task {
protected String description;
protected boolean isDone;
private String description;
private boolean isDone;

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

public String getStatusIcon() {
String getStatusIcon() {
return (isDone ? "\u2713" : "\u2718"); //return tick or X symbols
}

public void markAsDone() {
void markAsDone() {
this.isDone = true;
}

public boolean isDone() {
boolean isDone() {
return this.isDone;
}

public String getDescription() {
String getDescription() {
return this.description;
}

Expand Down
6 changes: 1 addition & 5 deletions src/main/java/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ String getOutput() {
return this.output;
}

String greet() { //duke greet
return "Hello! I'm Duke.\n" + "What can I do for you?\n";
}

void setToFarewell() {
output = "Bye. Hope to see you again soon!";
}
Expand Down Expand Up @@ -66,7 +62,7 @@ void setToFind(ArrayList<Task> relatedTasks, TaskList taskList, String findWord)
output = "Here are the matching tasks in your list:\n";
for (int i = 0; i < relatedTasks.size(); i++) {
int num = i + 1;
output += num + "." + relatedTasks.get(i);
output += num + "." + relatedTasks.get(i) + "\n";
}
}

Expand Down