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

[Li Beining] iP #453

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
3b19ba1
Add Gradle support
May 24, 2020
6433366
feat(main):Greet, Echo, Exit
dearvae Aug 20, 2020
2c6280c
feat(main):Add, List
dearvae Aug 20, 2020
a98a4aa
feat(Task): added new class Task
dearvae Aug 20, 2020
35cac77
feat(main):added ToDos, Events, Deadlines
dearvae Aug 20, 2020
167076e
test: added text-ui-test
dearvae Aug 20, 2020
d1fd443
feat(DukeException): added exception handle
dearvae Aug 20, 2020
e7b3189
feat(main):added delete
dearvae Aug 20, 2020
5000858
added enum and beautify code
dearvae Aug 20, 2020
c016462
add fileHelper and TaskList
dearvae Aug 28, 2020
ce40f56
deadline added dateTime
dearvae Aug 29, 2020
63df09e
merge branch level 8 to master
dearvae Aug 29, 2020
340c39e
make code more OOP
dearvae Aug 31, 2020
f9224cb
Divide classes into packages
dearvae Aug 31, 2020
5cebe5f
add Junit test for parser
dearvae Sep 1, 2020
0280f8e
Add JavaDoc comments
dearvae Sep 1, 2020
37c6aed
tweak the code to comply coding standard
dearvae Sep 1, 2020
1bea932
add feature find task by keyword
dearvae Sep 1, 2020
55fb07a
fix merge conflict
dearvae Sep 2, 2020
199363e
fix merge conflicts
dearvae Sep 2, 2020
3456e73
merge add_gradle_support
dearvae Sep 2, 2020
d9b7eaf
add GUI for Duke
dearvae Sep 2, 2020
6344b5f
fix bug
dearvae Sep 3, 2020
4e1a5f6
refactor code to comply javastandard style
dearvae Sep 9, 2020
15a0ebf
(TaskList) add assertion
dearvae Sep 9, 2020
3398724
Merge pull request #1 from dearvae/branch-A-Assertions
dearvae Sep 9, 2020
2171b87
refractor code for better codeQuality
dearvae Sep 9, 2020
df0f331
merge with master
dearvae Sep 9, 2020
ebee7eb
Merge pull request #2 from dearvae/branch-A-CodeQuality
dearvae Sep 9, 2020
b27cbc5
add extension help command
dearvae Sep 9, 2020
064e9bd
Merge pull request #3 from dearvae/branch-Extension
dearvae Sep 9, 2020
2ede15c
rename to KK
dearvae Sep 16, 2020
ddfa302
Update README.md
dearvae Sep 16, 2020
06cd463
Set theme jekyll-theme-leap-day
dearvae Sep 16, 2020
6fac0a1
add ui.png
dearvae Sep 16, 2020
c722ee3
update userguide
dearvae Sep 16, 2020
7b5db87
updated UI
dearvae Sep 18, 2020
f19f18a
update exception when create deadline object
dearvae Sep 18, 2020
2331709
fix bugs raised by peer comment
dearvae Oct 18, 2020
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
7 changes: 7 additions & 0 deletions data/duke.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
T | 1 | return book
T | 1 | yoyo
T | 1 | dsadas
E | 1 | dsadsad | dasdsadas dsad
D | 1 | dsdasd | 2/12/2010 17:22
T | 0 | dsadas
E | 0 | dsadas | dsad
43 changes: 37 additions & 6 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,41 @@
import Duke.command.Command;
import Duke.exceptions.DukeException;
import Duke.task.TaskList;
import Duke.utils.Parser;
import Duke.utils.Ui;

public class Duke {

private TaskList tasks;
private Ui ui;

public Duke(String path, String fileName) {
ui = new Ui();
tasks = new TaskList(path, fileName);
}

public void run() {
ui.showWelcome();
boolean isExit = false;
while (!isExit) {
try {
String fullCommand = ui.readCommand();
ui.showLine(); // show the divider line ("_______")
Command c = Parser.parse(fullCommand);
c.execute(tasks, ui);
isExit = c.isExit();
} catch (DukeException e) {
ui.showError(e.getMessage());
} finally {
ui.showLine();
}
}

ui.sayGoodBye();
}

public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
new Duke("data/", "duke.txt").run();
}

}
44 changes: 44 additions & 0 deletions src/main/java/Duke/command/AddCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package Duke.command;

import Duke.model.Deadline;
import Duke.model.Event;
import Duke.model.ToDo;
import Duke.task.Task;
import Duke.task.TaskList;
import Duke.utils.Ui;

public class AddCommand extends Command {
String taskType;

Choose a reason for hiding this comment

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

Shall we privatize variables for encapsulation? If I'm not mistaken, its part of the coding standard that this mod enforces

String info;

public AddCommand(String taskType, String info) {
this.taskType = taskType;
this.info = info;
}

@Override
public boolean isExit() {
return false;
}

@Override
public void execute(TaskList tasks, Ui ui) {

Task task;

if(taskType.equals("todo")) {
task = new ToDo(info);
} else if(taskType.equals("deadline")) {
String[] deadlineParts = info.split(" /by ");
task = new Deadline(deadlineParts[0], deadlineParts[1]);
} else { // event
String[] eventParts = info.split(" /at ");
task = new Event(eventParts[0], eventParts[1]);
}

tasks.addTask(task);

ui.showAddMessage(task, tasks);

}
}
9 changes: 9 additions & 0 deletions src/main/java/Duke/command/Command.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package Duke.command;

import Duke.task.TaskList;
import Duke.utils.Ui;

public abstract class Command {
public abstract boolean isExit();
public abstract void execute(TaskList tasks, Ui ui);
}
25 changes: 25 additions & 0 deletions src/main/java/Duke/command/DeleteCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package Duke.command;

import Duke.task.Task;
import Duke.task.TaskList;
import Duke.utils.Ui;

public class DeleteCommand extends Command{

private int index;
public DeleteCommand(int index) {
this.index = index;
}

@Override
public boolean isExit() {
return false;
}

@Override
public void execute(TaskList tasks, Ui ui) {
Task task = tasks.get(index);
tasks.remove(index);
ui.showRemovalMessage(task, tasks);
}
}
24 changes: 24 additions & 0 deletions src/main/java/Duke/command/DoneCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package Duke.command;

import Duke.task.Task;
import Duke.task.TaskList;
import Duke.utils.Ui;

public class DoneCommand extends Command {
private int index;
public DoneCommand(int index) {
this.index = index;
}

@Override
public boolean isExit() {
return false;
}

@Override
public void execute(TaskList tasks, Ui ui) {
Task task = tasks.get(index);
tasks.markAsDone(index);
ui.showDoneMessage(task);
}
}
16 changes: 16 additions & 0 deletions src/main/java/Duke/command/ExitCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package Duke.command;

import Duke.task.TaskList;
import Duke.utils.Ui;

public class ExitCommand extends Command {
@Override
public boolean isExit() {
return true;
}

@Override
public void execute(TaskList tasks, Ui ui) {
//do nothing
}
}
17 changes: 17 additions & 0 deletions src/main/java/Duke/command/ListCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package Duke.command;

import Duke.task.TaskList;
import Duke.utils.Ui;

public class ListCommand extends Command {

@Override
public boolean isExit() {
return false;
}

@Override
public void execute(TaskList tasks, Ui ui) {
ui.showListMessage(tasks);
}
}
7 changes: 7 additions & 0 deletions src/main/java/Duke/exceptions/DukeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package Duke.exceptions;

public class DukeException extends Exception {
public DukeException(String errorMessage) {

Choose a reason for hiding this comment

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

Can consider adding an empty line here so as to standardize with the rest of the files, just something trivial 👍

super(errorMessage);
}
}
49 changes: 49 additions & 0 deletions src/main/java/Duke/model/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package Duke.model;

import Duke.task.Task;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class Deadline extends Task {

private String time;
private LocalDate date;
private LocalDateTime dateTime;

public Deadline(String description, String time) {
super(description);
this.time = time;
String[] parts = time.split(" ");
String[] timeParts = parts[1].split(":");
int hour = Integer.parseInt(timeParts[0]);
int minute = Integer.parseInt(timeParts[1]);
date = LocalDate.parse(parts[0], DateTimeFormatter.ofPattern("d/MM/yyyy"));
dateTime = date.atTime(hour, minute);
}

public Deadline(boolean isDone, String description, String time) {
super(isDone, description);
this.time = time;
String[] parts = time.split(" ");
String[] timeParts = parts[1].split(":");
int hour = Integer.parseInt(timeParts[0]);
int minute = Integer.parseInt(timeParts[1]);
date = LocalDate.parse(parts[0], DateTimeFormatter.ofPattern("d/MM/yyyy"));
dateTime = date.atTime(hour, minute);
}

@Override
public String toString() {
return "[D]" + super.toString() + " (by: " + dateTime.format(DateTimeFormatter.ofPattern("MMM d yyyy, HH:mm")) + ")";
}

@Override
public String toStoreFormat(){
String type = "D";
String status = isDone ? "1" : "0";
String connect = " | ";
return type + connect + status + connect + description + connect + time;
}
}
30 changes: 30 additions & 0 deletions src/main/java/Duke/model/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package Duke.model;

import Duke.task.Task;

public class Event extends Task {
private String time;
public Event(String description, String time) {
super(description);
this.time = time;
}

public Event(boolean isDone, String description, String time) {
super(isDone, description);
this.time = time;
}

@Override
public String toString() {
return "[E]" + super.toString() + "(at: " + time + ")";
}

@Override
public String toStoreFormat(){
String type = "E";
String status = isDone ? "1" : "0";
String connect = " | ";
return type + connect + status + connect + description + connect + time;
}

}
27 changes: 27 additions & 0 deletions src/main/java/Duke/model/ToDo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package Duke.model;

import Duke.task.Task;

public class ToDo extends Task {

public ToDo(String description) {
super(description);
}

public ToDo(boolean isDone, String description) {
super(isDone, description);
}

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

@Override
public String toStoreFormat(){
String type = "T";
String status = isDone ? "1" : "0";
String connect = " | ";
return type + connect + status + connect + description;
}
}
32 changes: 32 additions & 0 deletions src/main/java/Duke/task/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package Duke.task;

public class Task {
protected boolean isDone;
protected String description;

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

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

public void markAsDone() {
isDone = true;
}

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

public String toString() {
return "[" + getStatusIcon() + "] " + description;
}

public String toStoreFormat(){
return "";
}
}
Loading