Skip to content
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
66 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
e4468fd
W2 - Level-1
ReignOfComputer Aug 22, 2019
f1bcc03
W2 - Level-2
ReignOfComputer Aug 22, 2019
ce3c6a2
W2 - Level-3 | A-Classes
ReignOfComputer Aug 22, 2019
a1d0e49
W2 - Level-4 | A-Inheritance
ReignOfComputer Aug 22, 2019
63f391d
W2 - A-TextUiTesting
ReignOfComputer Aug 22, 2019
9b3114a
W2 - Level-5 | A-Exceptions
ReignOfComputer Aug 22, 2019
87d04fc
W2 - Level-6 | A-Collections
ReignOfComputer Aug 22, 2019
1993700
W3 - Level-7
ReignOfComputer Sep 5, 2019
7d25f64
W3 - Level-8
ReignOfComputer Sep 5, 2019
ca79572
Merge branch 'branch-level-7'
ReignOfComputer Sep 5, 2019
b430600
Merge branch 'branch-level-8'
ReignOfComputer Sep 5, 2019
a27d0e0
Cleanup
ReignOfComputer Sep 5, 2019
d12d74d
Checkpoint
ReignOfComputer Sep 5, 2019
d599e58
W3 - A-MoreOOP
ReignOfComputer Sep 8, 2019
ed47830
W3 - A-Packages
ReignOfComputer Sep 8, 2019
4e40f25
W3 - A-JUnit
ReignOfComputer Sep 8, 2019
04709ef
W3 - A-Jar
ReignOfComputer Sep 8, 2019
ebbb385
Merge branch 'gradle'
ReignOfComputer Sep 8, 2019
bbef516
W3 - A-Gradle
ReignOfComputer Sep 8, 2019
afc4cf0
Checkpoint
ReignOfComputer Sep 8, 2019
3a1bf72
W3 - A-JavaDoc
ReignOfComputer Sep 13, 2019
1b04d7b
W3 - A-CodingStandard
ReignOfComputer Sep 13, 2019
e82e1ca
W3 - Level-9
ReignOfComputer Sep 13, 2019
4183818
Merge branch 'branch-A-JavaDoc'
ReignOfComputer Sep 13, 2019
f041f08
Merge branch 'branch-A-CodingStandard'
ReignOfComputer Sep 13, 2019
4fbd727
Merge branch 'branch-Level-9'
ReignOfComputer Sep 13, 2019
68a79df
Fix Parsing for Todo
ReignOfComputer Sep 13, 2019
ee1f0d0
W4 - A-Varargs
ReignOfComputer Sep 13, 2019
f7153d3
Checkpoint
ReignOfComputer Sep 13, 2019
f6d2a85
W4 - Level 10
ReignOfComputer Sep 15, 2019
21d1cf8
Merge branch 'branch-Level-10'
ReignOfComputer Sep 15, 2019
4a100f6
Merge branch 'branch-A-Varargs'
ReignOfComputer Sep 15, 2019
80eddee
Cleanup
ReignOfComputer Sep 15, 2019
85dbd20
W5 - A-CodeQuality
ReignOfComputer Sep 15, 2019
35debc2
Merge pull request #5 from ReignOfComputer/branch-A-CodeQuality
ReignOfComputer Sep 15, 2019
3894fd8
W5 - A-Lambdas
ReignOfComputer Sep 15, 2019
f31afb0
Merge pull request #6 from ReignOfComputer/branch-A-Lambdas
ReignOfComputer Sep 15, 2019
3238c78
W5 - A-Assertations
ReignOfComputer Sep 15, 2019
6d36279
W5 - A-Travis
ReignOfComputer Sep 15, 2019
d4e0b61
Explict Tests for Checkstyle
ReignOfComputer Sep 15, 2019
61fb6c5
Fix Broken Tests
ReignOfComputer Sep 15, 2019
68a6ad2
CI Status in Readme
ReignOfComputer Sep 15, 2019
3d2c4f9
Merge pull request #8 from ReignOfComputer/branch-A-Assertations
ReignOfComputer Sep 15, 2019
e9ffbb8
W5 - A-Streams
ReignOfComputer Sep 15, 2019
00f268a
Merge pull request #9 from ReignOfComputer/branch-A-Streams
ReignOfComputer Sep 15, 2019
17aef6a
Remove Redundant Code
ReignOfComputer Sep 15, 2019
002a959
W5 - C-Help
ReignOfComputer Sep 15, 2019
435b2c3
W5 - C-BetterSearch
ReignOfComputer Sep 15, 2019
b2ccb17
W5 - C-Statistics
ReignOfComputer Sep 15, 2019
ea45dba
HustlePad Personality
ReignOfComputer Sep 19, 2019
55b0669
Fix Missing Spaces
ReignOfComputer Sep 19, 2019
949fec2
Product Screenshot v1
ReignOfComputer Sep 19, 2019
f00b348
W6 - A-UserGuide
ReignOfComputer Sep 19, 2019
b49e8ed
shadowjar fix
ReignOfComputer Sep 19, 2019
5f14292
Set theme jekyll-theme-hacker
ReignOfComputer Sep 19, 2019
d55e710
Set theme jekyll-theme-hacker
ReignOfComputer Sep 19, 2019
82e9fcf
Set theme jekyll-theme-cayman
ReignOfComputer Sep 19, 2019
2e68aa4
JavaDocs V2
ReignOfComputer Sep 19, 2019
a248cd0
UserGuide V2
ReignOfComputer Sep 19, 2019
c8d2b18
UserGuide V3
ReignOfComputer Sep 19, 2019
e8cf2c0
UserGuide V4
ReignOfComputer Sep 19, 2019
bb4a3c4
JaVa WrItE oNcE rUn AnYwHeRe
ReignOfComputer Sep 20, 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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ src/main/resources/docs/
.DS_Store
*.iml
bin/

# Duke data files
/data/
2 changes: 2 additions & 0 deletions src/main/java/AddCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
public class AddCommand {
}
2 changes: 2 additions & 0 deletions src/main/java/Command.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
public class Command {
}
22 changes: 22 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class Deadline extends Task {

protected LocalDateTime by;

public Deadline(String description, String by) {
super(description);
this.by = LocalDateTime.parse(by, DateTimeFormatter.ofPattern("d/MM/yyyy Hmm"));
}

@Override
public String printSave() {
return "D | " + ((isDone) ? "1" : "0") + " | " + description + " | " + by;
}

@Override
public String toString() {
return "[D]" + super.toString() + " (by: " + by + ")";
}
}
2 changes: 2 additions & 0 deletions src/main/java/DeleteCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
public class DeleteCommand {
}
145 changes: 138 additions & 7 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,141 @@
import java.io.IOException;

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

/*
Alas - OOP, using a sledgehammer to crack a nut.
Yet another assignment with disproportionate workload #NUSLife
*/
private Storage storage;
private TaskList tasks;
private Ui ui;

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

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, storage);
isExit = c.isExit();
} catch (DukeException e) {
ui.showError(e.getMessage());
} finally {
ui.showLine();
}
}
}

public static void main(String[] args) throws DukeException, IOException {
new Duke("list.txt").run();
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Maybe it is advisable to remove the commented code if it is not used to avoid confusion.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

You caught me mid-refactor, laptop ran out of battery so I had to make a Checkpoint commit.

/* Scanner sc = new Scanner(System.in);



File f = new File("." + File.separator + "list.txt");
if (f.exists()) {
repeatList = Storage.loadList();
}

if (repeatList.size() != 0) {
System.out.println("Loaded " + repeatList.size() + " items.");
}

boolean byeHit = false;
String repeatStr = "";

while (!byeHit) {
repeatStr = sc.nextLine();
if (repeatStr.equals("bye")) {
byeHit = true;
Storage.saveList(repeatList);
System.out.println("Bye. Hope to see you again soon!");
} else if (repeatStr.equals("list")) {
System.out.println("Here are the tasks in your list:");
for (int i = 1; i <= repeatList.size(); i++) {
System.out.println(i + ". " + repeatList.get(i - 1));
}
} else if (repeatStr.contains("done")) {
try {
int target = parseInt(repeatStr.replaceAll("\\D+", "")) - 1;
repeatList.get(target).done();
System.out.println("Nice! I've marked this task as done: ");
System.out.println(" " + repeatList.get(target));
} catch (NumberFormatException ex) {
System.out.println("☹ OOPS!!! Invalid Information.");
} catch (IndexOutOfBoundsException ex) {
System.out.println("☹ OOPS!!! Invalid Information.");
}
} else if (repeatStr.contains("delete")) {
try {
int target = parseInt(repeatStr.replaceAll("\\D+", "")) - 1;
System.out.println("Noted. I've removed this task: ");
System.out.println(" " + repeatList.get(target));
repeatList.remove(target);
int size = repeatList.size();
System.out.println("You now have " + size + (size == 1 ? " task" : " tasks") + " in the list.");
} catch (NumberFormatException ex) {
System.out.println("☹ OOPS!!! Invalid Information.");
} catch (IndexOutOfBoundsException ex) {
System.out.println("☹ OOPS!!! Invalid Information.");
}
} else {
try {
String addTextDescription = "";
String addTextPeriod = "";
if (repeatStr.contains("todo")) {
addTextDescription = repeatStr.substring(repeatStr.lastIndexOf("todo ") + 5);
if (addTextDescription.length() == 0) {
throw new DukeException("☹ OOPS!!! The description of a todo cannot be empty.");
} else {
repeatList.add(new Todo(addTextDescription));
}
} else if (repeatStr.contains("deadline")) {
if (repeatStr.lastIndexOf("/by") == -1)
throw new DukeException("☹ OOPS!!! You are missing information.");
addTextDescription = repeatStr.substring(9, repeatStr.lastIndexOf("/by")).trim();
addTextPeriod = repeatStr.substring(repeatStr.lastIndexOf("/by ") + 3).trim();
if (addTextDescription.length() == 0 || addTextPeriod.length() == 0) {
throw new DukeException("☹ OOPS!!! You are missing information.");
} else {
repeatList.add(new Deadline(addTextDescription, addTextPeriod));
}
} else if (repeatStr.contains("event")) {
if (repeatStr.lastIndexOf("/at") == -1)
throw new DukeException("☹ OOPS!!! You are missing information.");
addTextDescription = repeatStr.substring(6, repeatStr.lastIndexOf("/at")).trim();
addTextPeriod = repeatStr.substring(repeatStr.lastIndexOf("/at ") + 3).trim();
if (addTextDescription.length() == 0 || addTextPeriod.length() == 0) {
throw new DukeException("☹ OOPS!!! You are missing information.");
} else {
repeatList.add(new Event(addTextDescription, addTextPeriod));
}
} else {
throw new DukeException("☹ OOPS!!! I'm sorry, but I don't know what that means :-(");
}
System.out.println("Got it. I've added this task: ");
int size = repeatList.size();
System.out.println(" " + repeatList.get(size - 1));
System.out.println("You now have " + size + (size == 1 ? " task" : " tasks") + " in the list.");
} catch (DukeException ex) {
System.out.println(ex.getMessage());
}
}
}
} */
}
5 changes: 5 additions & 0 deletions src/main/java/DukeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class DukeException extends Exception {
public DukeException(String message) {
super(message);
}
}
22 changes: 22 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class Event extends Task {

protected LocalDateTime at;

public Event(String description, String at) {
super(description);
this.at = LocalDateTime.parse(at, DateTimeFormatter.ofPattern("d/MM/yyyy Hmm"));
}

@Override
public String printSave() {
return "E | " + ((isDone) ? "1" : "0") + " | " + description + " | " + at;
}

@Override
public String toString() {
return "[E]" + super.toString() + " (at: " + at + ")";
}
}
2 changes: 2 additions & 0 deletions src/main/java/ExitCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
public class ExitCommand {
}
2 changes: 2 additions & 0 deletions src/main/java/Parser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
public class Parser {
}
54 changes: 54 additions & 0 deletions src/main/java/Storage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

public class Storage {

private String filePath;

public Storage(String filePath) {
this.filePath = filePath;
}

public void save(ArrayList<Task> repeatList) throws IOException {
FileWriter fw = new FileWriter(filePath);
for (Task t : repeatList) {
fw.write(t.printSave() + System.lineSeparator());
}
fw.close();
}

public ArrayList<Task> load() throws FileNotFoundException, DukeException {
ArrayList<Task> taskList = new ArrayList<>();
File dataFile = new File(filePath);
Scanner sc = new Scanner(dataFile);
while (sc.hasNext()) {
String line = sc.nextLine();
String[] lineSplit = line.split(" | ");
try {
switch (line.charAt(0)) {
case 'T':
taskList.add(new Todo(lineSplit[4]));
break;
case 'D':
taskList.add(new Deadline(lineSplit[4], lineSplit[6]));
break;
case 'E':
taskList.add(new Event(lineSplit[4], lineSplit[6]));
break;
default:
throw new DukeException("☹ OOPS!!! Invalid data loaded.");
}
if (lineSplit[2].equals("1")) {
taskList.get(taskList.size() - 1).done();
}
} catch (IndexOutOfBoundsException ex) {
throw new DukeException("☹ OOPS!!! Invalid data loaded.");
}
}
return taskList;
}
}
26 changes: 26 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
public class Task {
protected String description;
protected boolean isDone;

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

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

public void done() {
isDone = true;
}

public String printSave() {
return "T | " + ((isDone) ? "1" : "0") + " | " + description;
}

@Override
public String toString() {
return "[" + getStatusIcon() + "]" + " " + description;
}
}
2 changes: 2 additions & 0 deletions src/main/java/TaskList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
public class TaskList {
}
16 changes: 16 additions & 0 deletions src/main/java/Todo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
public class Todo extends Task {

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

@Override
public String printSave() {
return "T | " + ((isDone) ? "1" : "0") + " | " + description;
}

@Override
public String toString() {
return "[T]" + super.toString();
}
}
9 changes: 9 additions & 0 deletions src/main/java/Ui.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
public class Ui {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It would be better if there can be more functionality to represent interaction with users, including the different response messages.


public Ui() { }

public void showWelcome() {
System.out.println("Hello! I'm Duke.");
System.out.println("What can I OOP for you today?");
}
}
10 changes: 10 additions & 0 deletions text-ui-test/EXPECTED.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Hello! I'm Duke
What can I do for you?
Got it. I've added this task:
[D][✘] do homework (by: no idea :-p)
You now have 1 task in the list.
Nice! I've marked this task as done:
[D][✓] do homework (by: no idea :-p)
Here are the tasks in your list:
1. [D][✓] do homework (by: no idea :-p)
Bye. Hope to see you again soon!
4 changes: 4 additions & 0 deletions text-ui-test/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
deadline do homework /by no idea :-p
done 1
list
bye
21 changes: 21 additions & 0 deletions text-ui-test/runtest.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@ECHO OFF

REM create bin directory if it doesn't exist
if not exist ..\bin mkdir ..\bin

REM delete output from previous run
del ACTUAL.TXT

REM compile the code into the bin folder
javac -cp ..\src -Xlint:none -d ..\bin ..\src\main\java\Duke.java
IF ERRORLEVEL 1 (
echo ********** BUILD FAILURE **********
exit /b 1
)
REM no error here, errorlevel == 0

REM run the program, feed commands from input.txt file and redirect the output to the ACTUAL.TXT
java -classpath ..\bin Duke < input.txt > ACTUAL.TXT

REM compare the output to the expected output
FC ACTUAL.TXT EXPECTED.TXT