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

[Kaitlyn] iP #461

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
3b19ba1
Add Gradle support
May 24, 2020
456de8d
Level 1 completed
kaitlynng Aug 18, 2020
6e2b2a1
Bot now speaks russian
kaitlynng Aug 18, 2020
0d1b9a3
Level 3 done
kaitlynng Aug 19, 2020
90ef94f
Created Task class
kaitlynng Aug 19, 2020
ae618f8
Done level 4
kaitlynng Aug 20, 2020
0fa0977
Done A-TextUiTesting
kaitlynng Aug 20, 2020
403e28c
Done Level 5
kaitlynng Aug 20, 2020
1b2ebe2
Done Level 6
kaitlynng Aug 20, 2020
46f1d9a
Added enums
kaitlynng Aug 20, 2020
3f08797
Add Level-7 increment
kaitlynng Aug 30, 2020
299b09a
Add Level-8
kaitlynng Aug 30, 2020
730d194
switch to using LocalDateTime
kaitlynng Aug 30, 2020
b533b2f
Merge branch 'branch-Level-8'
kaitlynng Aug 30, 2020
289082d
Add A-MoreOOP
kaitlynng Aug 31, 2020
32469b6
Add A-Packages
kaitlynng Aug 31, 2020
24ca469
Add A-JUnit
kaitlynng Aug 31, 2020
cb051f4
Add A-JavaDoc
kaitlynng Sep 1, 2020
8be86c4
Add A-CodingStandard
kaitlynng Sep 1, 2020
491a55a
Merge tag 'A-CodingStandard'
kaitlynng Sep 1, 2020
ceb57be
Merge branch 'add-gradle-support' into branch-A-Gradle
kaitlynng Sep 1, 2020
398dd04
Add Level-10
kaitlynng Sep 8, 2020
00e31b4
Add A-Assertions
kaitlynng Sep 8, 2020
ef0e879
Merge pull request #1 from kaitlynng/A-Assertions
kaitlynng Sep 8, 2020
4a7970e
Revert "Add A-Assertions"
kaitlynng Sep 8, 2020
d6271e9
Merge pull request #2 from kaitlynng/revert-1-A-Assertions
kaitlynng Sep 8, 2020
bae37bd
Add Level-9
kaitlynng Sep 17, 2020
98f98c4
Add A-Assertions
kaitlynng Sep 17, 2020
a599370
Add C-Update
kaitlynng Sep 18, 2020
d03ab6c
Add A-CodeQuality
kaitlynng Sep 18, 2020
ddf8545
Merge pull request #3 from kaitlynng/branch-A-CodeQuality
kaitlynng Sep 18, 2020
46fa9d9
Add A-UserGuide
kaitlynng Sep 18, 2020
0cb4f87
Update README.md
kaitlynng Sep 18, 2020
7d6cd58
Add A-BetterGUI
kaitlynng Sep 18, 2020
1bb0432
Add more GUI improvements
kaitlynng Sep 18, 2020
2bca07a
minor changes
kaitlynng Sep 18, 2020
9829b69
Resize dialogbox
kaitlynng Sep 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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Duke project template
# duke.Duke project template

This is a project template for a greenfield Java project. It's named after the Java mascot _Duke_. Given below are instructions on how to use it.

Expand All @@ -15,7 +15,7 @@ Prerequisites: JDK 11, update Intellij to the most recent version.
1. Click `Open or Import`.
1. Select the project directory, and click `OK`
1. If there are any further prompts, accept the defaults.
1. After the importing is complete, locate the `src/main/java/Duke.java` file, right-click it, and choose `Run Duke.main()`. If the setup is correct, you should see something like the below:
1. After the importing is complete, locate the `src/main/java/duke.Duke.java` file, right-click it, and choose `Run duke.Duke.main()`. If the setup is correct, you should see something like the below:
```
Hello from
____ _
Expand Down
4 changes: 4 additions & 0 deletions data/tasks.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
duke.task.Task list (Last updated Sep 1 2020, 04:37:04 AM):
1. [T][✓] hello
2. [D][✗] homework (by: Mar 3 2020)
3. [E][✓] finish (at: Mar 4 2021, 12:00:00 PM)
10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

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

import duke.command.Command;
import duke.parser.Parser;
import duke.storage.Storage;
import duke.task.TaskList;
import duke.ui.Ui;

public class Duke {

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

public Duke(String filePath) {
this.ui = new Ui();
this.storage = new Storage(filePath);
try {
tasks = new TaskList(storage.load());
ui.showLoadedTasks(tasks);
} catch (DukeException e) {
ui.showLoadingError(e.getMessage());
tasks = new TaskList();
}
}

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

public static void main(String[] args) {
new Duke("data/tasks.txt").run();
}

}
7 changes: 7 additions & 0 deletions src/main/java/duke/DukeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package duke;

public class DukeException extends Exception {
public DukeException(String message) {
super(message);
}
}
25 changes: 25 additions & 0 deletions src/main/java/duke/command/ByeCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package duke.command;

import duke.*;

Choose a reason for hiding this comment

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

Would it be possible to avoid wildcard imports?

import duke.storage.Storage;
import duke.task.TaskList;
import duke.ui.Ui;

public class ByeCommand extends Command {

public ByeCommand() {
super();
this.cmd = CMD.BYE;
this.isExit = true;
}

@Override
public void execute(TaskList taskList, Ui ui, Storage storage) throws DukeException {
ui.display("OKAIS I IZ GOIN 2 NOM BYEEEEE C U !!!1!1!!");
}

@Override
public String toString() {
return cmd.toString();
}
}
12 changes: 12 additions & 0 deletions src/main/java/duke/command/CMD.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package duke.command;

public enum CMD {

Choose a reason for hiding this comment

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

I think enum names should be written in PascalCase based on the coding standard? 🤔

BYE,
LIST,
TODO,
DEADLINE,
EVENT,
DONE,
DELETE,
DEFAULT
}
29 changes: 29 additions & 0 deletions src/main/java/duke/command/Command.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package duke.command;

import duke.*;
import duke.storage.Storage;
import duke.task.TaskList;
import duke.ui.Ui;

public class Command {
protected CMD cmd;
protected boolean isExit;

public Command() {
this.cmd = CMD.DEFAULT;
this.isExit = false;
}

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

public void execute(TaskList taskList, Ui ui, Storage storage) throws DukeException {
ui.display("CAN I HAZ CHEEZBURGER?");
}

@Override
public String toString() {
return cmd.toString();
}
}
30 changes: 30 additions & 0 deletions src/main/java/duke/command/DeadlineCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package duke.command;

import duke.*;
import duke.storage.Storage;
import duke.task.TaskList;
import duke.ui.Ui;

public class DeadlineCommand extends Command {
private String taskName;
private String by;

public DeadlineCommand(String taskName, String by) {
super();
this.cmd = CMD.DEADLINE;
this.taskName = taskName;
this.by = by;
}

@Override
public void execute(TaskList taskList, Ui ui, Storage storage) throws DukeException {
ui.display("I PUT NEW TING IN DA LIST\n " + taskList.addDeadline(this.taskName, this.by)
+ "\nNAO U HAS " + taskList.getNumberOfTasks() + " FINGS IN DA LIST LULZIES");
storage.save(taskList);
}

@Override
public String toString() {
return cmd.toString() + ": " + taskName + "(" + by + ")";
}
}
28 changes: 28 additions & 0 deletions src/main/java/duke/command/DeleteCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package duke.command;

import duke.*;
import duke.storage.Storage;
import duke.task.TaskList;
import duke.ui.Ui;

public class DeleteCommand extends Command {
private int idx;
Copy link

Choose a reason for hiding this comment

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

Perhaps change this to index? In my opinion it's more understandable from the get go and it's not too many more characters 😉

public DeleteCommand(int idx) {
super();
this.cmd = CMD.DONE;
this.idx = idx;
}

@Override
public void execute(TaskList taskList, Ui ui, Storage storage) throws DukeException {
ui.display("TASK IZ NAO DELETZ!!!!1!11!\n" + " "
+ taskList.popTask(this.idx)
+ "\nNAO U HAS " + taskList.getNumberOfTasks() + " FINGS IN DA LIST LULZIES");
storage.save(taskList);
}

@Override
public String toString() {
return cmd.toString() + ": " + idx;
}
}
28 changes: 28 additions & 0 deletions src/main/java/duke/command/DoneCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package duke.command;

import duke.*;
import duke.storage.Storage;
import duke.task.TaskList;
import duke.ui.Ui;

public class DoneCommand extends Command {
private int idx;
public DoneCommand(int idx) {
super();
this.cmd = CMD.DONE;
this.idx = idx;
}

@Override
public void execute(TaskList taskList, Ui ui, Storage storage) throws DukeException {
taskList.markTaskAsDone(this.idx);
storage.save(taskList);
ui.display("TASK IZ NAO DUNZ!!!!1!11!\n" + " " + taskList.getTaskByIdx(this.idx));
}

@Override
public String toString() {
return cmd.toString() + ": " + idx;
}
}

30 changes: 30 additions & 0 deletions src/main/java/duke/command/EventCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package duke.command;

import duke.*;
import duke.storage.Storage;
import duke.task.TaskList;
import duke.ui.Ui;

public class EventCommand extends Command {
private String taskName;
private String by;

public EventCommand(String taskName, String by) {
super();
this.cmd = CMD.EVENT;
this.taskName = taskName;
this.by = by;
}

@Override
public void execute(TaskList taskList, Ui ui, Storage storage) throws DukeException {
ui.display("I PUT NEW TING IN DA LIST\n " + taskList.addEvent(this.taskName, this.by)
+ "\nNAO U HAS " + taskList.getNumberOfTasks() + " FINGS IN DA LIST LULZIES");
storage.save(taskList);
}

@Override
public String toString() {
return cmd.toString() + ": " + taskName + "(" + by + ")";
}
}
51 changes: 51 additions & 0 deletions src/main/java/duke/command/ListCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package duke.command;

import duke.*;
import duke.datetime.DateTimeUtility;
import duke.storage.Storage;
import duke.task.TaskList;
import duke.ui.Ui;

public class ListCommand extends Command {
private String by;

public ListCommand() {
super();
this.by = "";
this.cmd = CMD.LIST;
}

public ListCommand(String by) {
this();
this.by = DateTimeUtility.formatString(by);
}

@Override
public void execute(TaskList taskList, Ui ui, Storage storage) throws DukeException {

Choose a reason for hiding this comment

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

Do you think the nesting may be a bit deep here? I tend to find nested if-else hard to read when it goes down to 3-4 layers. One possible way of avoiding this:

if (taskList.isEmpty()) {
    ui.display("UR LIST HAZ NUTHIN LOLOL");
    return; // Stop the rest of the method from executing
}

if (by.isEmpty()) {
/* continue from here */

if (taskList.isEmpty()) {
ui.display("UR LIST HAZ NUTHIN LOLOL");
} else {
if (this.by.isEmpty()) {

Choose a reason for hiding this comment

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

Maybe the this keyword can be removed?

ui.display("U HAS DEES TINGS IN UR LIST.\n" + taskList.toString());
} else {
try {
String ret = TaskList.tasks2String(taskList.filterTasksByDate(this.by));
if (ret.isEmpty()) {
ui.display("U HAZ NUTHIN DUE/HAPPENIN BY "
+ DateTimeUtility.formatString(this.by) + "!! LULZIES");
} else {
ui.display("U HAS DEES TINGS IN UR LIST DAT R DUE/HAPPENIN BY "
+ DateTimeUtility.formatString(this.by) + ": \n"
+ ret);
}

} catch (DukeException e) {} //exception will never be reached
}
}
}

@Override
public String toString() {
return cmd.toString() + (by.isEmpty() ? "" : " (" + by + ")");
}
}
28 changes: 28 additions & 0 deletions src/main/java/duke/command/TodoCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package duke.command;

import duke.*;
import duke.storage.Storage;
import duke.task.TaskList;
import duke.ui.Ui;

public class TodoCommand extends Command {
private String taskName;

public TodoCommand(String taskName) {
super();
this.cmd = CMD.TODO;
this.taskName = taskName;
}

@Override
public void execute(TaskList taskList, Ui ui, Storage storage) throws DukeException {
ui.display("I PUT NEW TING IN DA LIST\n " + taskList.addTodo(this.taskName)
+ "\nNAO U HAS " + taskList.getNumberOfTasks() + " FINGS IN DA LIST LULZIES");
storage.save(taskList);
}

@Override
public String toString() {
return cmd.toString() + ": " + taskName;
}
}
7 changes: 7 additions & 0 deletions src/main/java/duke/datetime/DateTimeFormat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package duke.datetime;

public enum DateTimeFormat {
String,

Choose a reason for hiding this comment

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

I like the use of an enum to keep track of valid & invalid formats. Much better than using integer status codes. Perhaps these should be in uppercase as it is an enum? I noticed a few other variables in a similar position.

Date,
DateTime,
}
Loading