Skip to content
Open
Show file tree
Hide file tree
Changes from 14 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?

}
}
30 changes: 24 additions & 6 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
import java.io.FileNotFoundException;

public class Duke {
private Storage storage;
private TaskList tasks;
private Ui ui;
private Parser parser;

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

public void run() {
this.parser = new Parser(ui, tasks, storage);
parser.run();
}

public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
new Duke("C:\\Users\\e0316059\\Desktop\\cs2103 ip\\src\\main\\java\\data\\duke.txt").run();
}
}
11 changes: 11 additions & 0 deletions src/main/java/DukeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public class DukeException extends Exception {
private String type;

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

public String getType() {
return this.type;
}
}
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?

}
}
79 changes: 79 additions & 0 deletions src/main/java/Parser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import java.util.Scanner;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class Parser {
private static Ui ui;
private static TaskList tasks;
private static Storage storage;

public Parser(Ui ui, TaskList tasks, Storage storage) {
this.ui = ui;
this.tasks = tasks;
this.storage = storage;
}

public static void run() {
Scanner scanner = new Scanner(System.in);
ui.printLogo();
ui.greet();
while (scanner.hasNextLine()) {
String command = scanner.nextLine();
try {
handleCommand(command);
} catch (DukeException e) {
ui.showCommandError(e);
}
}
}

/**
* this method handles two types of error: invalid input (does not contain todo/deadline/event)

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 the javadoc header comment start in the form of Handles ...?

* 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)
*/
public static void handleCommand(String command) throws DukeException {
if (command.equals("bye")) {
ui.exit();
} else if (command.equals("list")) {
ui.printList(tasks.getTasks());
} else if (command.split(" ")[0].equals("done")) {
int index = Integer.parseInt(command.split(" ")[1]);
tasks.done(index - 1);
storage.record(tasks.getTasks());
} else if (command.split(" ")[0].equals("delete")) {
tasks.delete(Integer.parseInt(command.split(" ")[1]));
storage.record(tasks.getTasks());
} else if (command.split(" ")[0].equals("todo")) {
String taskcommand = command.replace("todo", "");
if (!taskcommand.equals("")) {
tasks.add(new ToDo(taskcommand));
} else {
throw new DukeException("EmptyToDo");
}
storage.record(tasks.getTasks());
} 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");
tasks.add(new Deadline(taskcommand, LocalDateTime.parse(time, formatter)));
} else {
throw new DukeException("EmptyDeadline");
}
storage.record(tasks.getTasks());
} 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");
tasks.add(new Deadline(taskcommand, LocalDateTime.parse(time, formatter)));
} else {
throw new DukeException("EmptyEvent");
}
storage.record(tasks.getTasks());
} else {
throw new DukeException("invalid");
}
}
}
80 changes: 80 additions & 0 deletions src/main/java/Storage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
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 Storage {
private static String filePath;
private static Ui ui;

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

public static ArrayList<Task> load() throws FileNotFoundException {
File file = new File(filePath);
Scanner sc = new Scanner(file);
ArrayList<Task> tasks = new ArrayList<Task>();
while (sc.hasNextLine()) {
String[] data = sc.nextLine().split(" \\| ");
if (data[0].equals("T")) {
ToDo todo = new ToDo(data[2]);
tasks.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);
tasks.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);
tasks.add(event);
if (data[1].equals("1")) {
event.setDone();
}
}
}
return tasks;
}

public static void writeToFile(ArrayList<Task> tasks) throws IOException {
FileWriter fileWriter = new FileWriter(filePath);
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().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HHmm"));
fileWriter.write(text + System.lineSeparator());
} else if (task instanceof Event) {
String text = "E | " + (task.getStatus() ? "1" : "0") + " | " + task.getCommand()
+ " | " + ((Event) task).getTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HHmm"));
fileWriter.write(text + System.lineSeparator());
}
}
fileWriter.close();
}

public static void record(ArrayList<Task> tasks) {
try {
writeToFile(tasks);
} catch (IOException e) {
ui.showIOException(e);

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 the method name showIOException be showIoException?

}
}

}
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;
}
}
}
36 changes: 36 additions & 0 deletions src/main/java/TaskList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import java.util.ArrayList;

public class TaskList {
private static ArrayList<Task> tasks;
private static Ui ui;

public TaskList(ArrayList<Task> tasks) {
this.tasks = tasks;
this.ui = new Ui();
}

public TaskList() {
this.tasks = new ArrayList<Task>();
this.ui = new Ui();
}

public ArrayList<Task> getTasks() {
return this.tasks;
}

public static void add(Task task) {
tasks.add(task);
ui.add(task, tasks);
}

public static void done(int n) {
tasks.get(n-1).setDone();
ui.done(n, tasks);
}

public static void delete(int n) {
ui.delete(n, tasks);
tasks.remove(n-1);
ui.count(tasks);
}
}
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();
}
}
Loading