Skip to content
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
3b19ba1
Add Gradle support
May 24, 2020
9f821c0
complete level1
e0316059 Aug 29, 2020
f62a7f3
complete level 2
e0316059 Aug 29, 2020
6b59ff6
complete level 3
e0316059 Aug 29, 2020
c1a2ea9
complete level 4
e0316059 Aug 29, 2020
182a931
text-ui-test
e0316059 Aug 30, 2020
cba08aa
complete level 5
e0316059 Aug 30, 2020
31df1b6
modify runtest.sh
e0316059 Aug 30, 2020
8cc05e0
complete level 6
e0316059 Aug 30, 2020
518cfd9
complete level 7
e0316059 Aug 30, 2020
b813133
complete level 8
e0316059 Aug 30, 2020
cfa7a2b
solve merge conflict
e0316059 Aug 30, 2020
8eba1f4
add more oop
e0316059 Aug 31, 2020
6f69ae0
dummy junit test
e0316059 Aug 31, 2020
ada2f9c
add JUnit Test
e0316059 Aug 31, 2020
376be01
create jar file; add java docs
e0316059 Sep 7, 2020
b7ea569
modifing java doc
e0316059 Sep 7, 2020
a512baa
modify code according to coding standard
e0316059 Sep 7, 2020
d9f7624
complete level 9
e0316059 Sep 7, 2020
e0f008f
debug
e0316059 Sep 7, 2020
ec7e0d3
Merge commit 'd9f762443958872bf6d4825efc715864622242ca'
e0316059 Sep 7, 2020
f8b1a63
Merge branch 'branch-Level-9'
e0316059 Sep 7, 2020
b531cfc
Merge branch 'add-gradle-support'
e0316059 Sep 8, 2020
9975db1
add basic gui
e0316059 Sep 18, 2020
4092f83
finish gui
e0316059 Sep 18, 2020
0730d55
formatting code
e0316059 Sep 18, 2020
060dc2a
no message
e0316059 Sep 18, 2020
bc38e89
Merge commit '4092f83a3836202eaf361ceb09152fe42a40f7d4'
e0316059 Sep 18, 2020
16b68c6
Merge branch 'branch-Level-10'
e0316059 Sep 18, 2020
384a6b9
test
e0316059 Sep 18, 2020
713f827
use assertions
e0316059 Sep 18, 2020
94a4c3d
improve code quality
e0316059 Sep 18, 2020
d515ee4
Merge pull request #1 from e0316059/branch-A-Assertions
e0316059 Sep 18, 2020
475d7e2
Merge branch 'master' into branch-A-CodeQuality
e0316059 Sep 18, 2020
de7ce07
Merge pull request #2 from e0316059/branch-A-CodeQuality
e0316059 Sep 18, 2020
da2dde7
complete C-Statistics
e0316059 Sep 21, 2020
1c80fa5
add ui screenshot
e0316059 Sep 21, 2020
3c22118
add user guide
e0316059 Sep 21, 2020
236630d
using java fxml
e0316059 Sep 21, 2020
1744f64
fix data loading bug
e0316059 Sep 21, 2020
674b1eb
organize into packages
e0316059 Sep 21, 2020
be78175
add line seperator to ui
e0316059 Sep 21, 2020
07e7a7a
fix data loading bug
e0316059 Sep 21, 2020
32b0be5
fix done command error
e0316059 Sep 21, 2020
038d9e5
add greeting message in gui
e0316059 Sep 21, 2020
a83a8bc
add checkstyle configuration
e0316059 Sep 21, 2020
f9df5c3
fix checkstyle error
e0316059 Sep 21, 2020
58335be
modify user guide
e0316059 Sep 21, 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
21 changes: 21 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class Deadline extends Task{
private LocalDateTime time;

public Deadline(String command, LocalDateTime time) {
super(command);
this.time = time;
}

public LocalDateTime getTime() {
return this.time;
}
Comment on lines +25 to +27

Choose a reason for hiding this comment

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

According to the module's coding standards, should a javadoc comment exist above the method? The same comment for all other public methods.


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

Choose a reason for hiding this comment

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

According to the module's coding standard, should the + after "(by: " be on the second line instead of the first line?

}
}
192 changes: 191 additions & 1 deletion src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,200 @@
import java.awt.*;
import java.util.List;
import java.util.Scanner;
import java.util.ArrayList;
import java.io.File;
import java.io.FileWriter;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;


public class Duke {
private static List<Task> tasks = new ArrayList<>();

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

Scanner scanner = new Scanner(System.in);

try {
readFile();
} catch (FileNotFoundException e) {
System.out.println("File not found");
}
greet();
while (scanner.hasNextLine()) {
String command = scanner.nextLine();
try {
handleCommand(command);
} catch (DukeException e) {
System.out.println(e.getMessage());
}
}
}

private static void greet() {
System.out.println("Hello! I'm Duke\n What can I do for you?");
}

private static void exit() {
System.out.println("Bye. Hope to see you again soon!");
}

private static void echo(String command) {
System.out.println("" + command);
}

private static void add(Task task) {
tasks.add(task);
System.out.println("Got it. I've added this task:\n" + task.toString()
+ "\n Now you have " + tasks.size() + " tasks in the list.");
}

private static void done(Task task) {
task.setDone();
System.out.println("Nice! I've marked this task as done:\n" + task.toString());
}

private static void delete(int index) {
System.out.println("Noted. I've removed this task:\n" + tasks.get(index-1).toString());
tasks.remove(index-1);
System.out.println("Now you have " + tasks.size() + " tasks in the list.");
}

private static void printList() {
System.out.println("Here are the tasks in your list:");
for (int i = 0; i < tasks.size(); i++) {
if (tasks.get(i) != null) {
System.out.println((i + 1) + ". " + tasks.get(i).toString());
}
}
}

/**
* this method handles two types of error: invalid input (does not contain todo/deadline/event)
* and empty task (if the input starts with todo/deadline/event and the content is not empty,
* it is assumed that the input has correct structure)
*/
Copy link

Choose a reason for hiding this comment

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

As per iP task on code quality, should the JavaDoc contain descriptions on the input parameter?

private static void handleCommand(String command) throws DukeException {
if (command.equals("bye")) {
exit();
} else if (command.equals("list")) {
printList();
} else if (command.split(" ")[0].equals("done")) {
int index = Integer.parseInt(command.split(" ")[1]);
done(tasks.get(index - 1));
try {
writeToFile();
} catch (IOException e) {
System.out.println("Oops! " + e.getMessage());
}
} else if (command.split(" ")[0].equals("delete")) {
delete(Integer.parseInt(command.split(" ")[1]));
try {
writeToFile();
} catch (IOException e) {
System.out.println("Oops! " + e.getMessage());
}
} else if (command.split(" ")[0].equals("todo")) {
String taskcommand = command.replace("todo", "");
if (!taskcommand.equals("")) {
add(new ToDo(taskcommand));
} else {
throw new DukeException("EmptyToDo");
}
try {
writeToFile();
} catch (IOException e) {
System.out.println("Oops! " + e.getMessage());
}
} else if (command.split(" ")[0].equals("deadline")) {
String taskcommand = command.split("/")[0].replace("deadline", "");
if (!taskcommand.equals("")) {
String time = command.split("/")[1].replace("by ", "");
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HHmm");
add(new Deadline(taskcommand, LocalDateTime.parse(time, formatter)));
} else {
throw new DukeException("EmptyDeadline");
}
try {
writeToFile();
} catch (IOException e) {
System.out.println("Oops! " + e.getMessage());
}
} else if (command.split(" ")[0].equals("event")) {
String taskcommand = command.split("/")[0].replace("event", "");
if (!taskcommand.equals("")) {
String time = command.split("/")[1].replace("at ", "");
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HHmm");
add(new Deadline(taskcommand, LocalDateTime.parse(time, formatter)));
} else {
throw new DukeException("EmptyEvent");
}
try {
writeToFile();
} catch (IOException e) {
System.out.println("Oops! " + e.getMessage());
}
} else {
throw new DukeException("invalid");
}
}

private static void readFile() throws FileNotFoundException {
Copy link

Choose a reason for hiding this comment

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

As per iP task on code quality, should this function be accompanied with a JavaDoc?

File file = new File("C:\\Users\\e0316059\\Desktop\\cs2103 ip\\src\\main\\java\\data\\duke.txt");
Scanner sc = new Scanner(file);
while (sc.hasNextLine()) {
String[] data = sc.nextLine().split(" \\| ");
if (data[0].equals("T")) {
ToDo todo = new ToDo(data[2]);
add(todo);
if (data[1].equals("1")) {
todo.setDone();
}
} else if (data[0].equals("D")) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HHmm");
LocalDateTime time = LocalDateTime.parse(data[3], formatter);
Deadline deadline = new Deadline(data[2], time);
add(deadline);
if (data[1].equals("1")) {
deadline.setDone();
}
} else if (data[0].equals("E")) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HHmm");
LocalDateTime time = LocalDateTime.parse(data[3], formatter);
Event event = new Event(data[2], time);
add(event);
if (data[1].equals("1")) {
event.setDone();
}
}
}
}

private static void writeToFile() throws IOException {
FileWriter fileWriter = new FileWriter("C:\\Users\\e0316059\\Desktop\\cs2103 ip\\src\\main\\java\\data\\duke.txt");
for (int i = 0; i < tasks.size(); i++) {
Task task = tasks.get(i);
if (task instanceof ToDo) {
String text = "T | " + (task.getStatus() ? "1" : "0") + " | " + task.getCommand();
fileWriter.write(text + System.lineSeparator());
} else if (task instanceof Deadline) {
String text = "D | " + (task.getStatus() ? "1" : "0") + " | " + task.getCommand()
+ " | " + ((Deadline) task).getTime();
fileWriter.write(text + System.lineSeparator());
} else if (task instanceof Event) {
String text = "E | " + (task.getStatus() ? "1" : "0") + " | " + task.getCommand()
+ " | " + ((Event) task).getTime();
fileWriter.write(text + System.lineSeparator());
}
}
fileWriter.close();
}
}
20 changes: 20 additions & 0 deletions src/main/java/DukeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
public class DukeException extends Exception {
private String type;

public DukeException (String type) {
this.type = type;
}

public String getMessage() {
if (type.equals("EmptyToDo")) {
return "OOPS!!! The description of a todo cannot be empty.";
}
if (type.equals("EmptyDeadline")) {
return "OOPS!!! The description of a deadline cannot be empty.";
}
if (type.equals("EmptyEvent")) {
return "OOPS!!! The description of a event cannot be empty.";
}
return "OOPS!!! I'm sorry, but I don't know what that means :-(";
}
}
21 changes: 21 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class Event extends Task {
private LocalDateTime time;

public Event(String command, LocalDateTime time) {
super(command);
this.time = time;
}

public LocalDateTime getTime() {
return this.time;
}

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

Choose a reason for hiding this comment

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

According to the module's coding standard, should the + after "(at: " be on the second line instead of the first line?

}
}
30 changes: 30 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
public class Task {
protected String command;
protected boolean isDone;

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

public String getCommand() {
return this.command;
}

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

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

@Override
public String toString() {
if (isDone) {
return "[\u2713]" + this.command;
} else {
return "[\u2718]" + this.command;
}
}
}
11 changes: 11 additions & 0 deletions src/main/java/ToDo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public class ToDo extends Task {

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

@Override
public String toString(){
return "[T]" + super.toString();
}
}
4 changes: 4 additions & 0 deletions src/main/java/data/Duke.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
T | 0 | return book
D | 0 | meeting | 2020-08-31T12:00
D | 0 | homework | 2020-08-31T23:59
T | 0 | quiz
14 changes: 12 additions & 2 deletions text-ui-test/EXPECTED.TXT
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
Hello from
____ _
| _ \ _ _| | _____
| | | | | | | |/ / _ \
| |_| | |_| | < __/
|____/ \__,_|_|\_\___|

Hello! I'm Duke
What can I do for you?
Got it. I've added this task:
[T][✘] borrow book
Now you have 1 tasks in the list.
Got it. I've added this task:
[D][✘] return book (by: Sunday)
Now you have 2 tasks in the list.
Got it. I've added this task:
[E][✘] meeting (at: 1200)
Now you have 3 tasks in the list.
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 @@
todo borrow book
deadline return book /by Sunday
event meeting /at 1200
bye
Loading