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

[Cheah Yan (Xie Yan)] iP #486

Open
wants to merge 64 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
d839859
Add Gradle support
May 24, 2020
11af5b5
Level-1
CheahYan Aug 19, 2021
0caf30f
Level-2
CheahYan Aug 19, 2021
b228ba5
Level-3
CheahYan Aug 19, 2021
07274fb
Level-4
CheahYan Aug 21, 2021
0b02f80
Level-5
CheahYan Aug 21, 2021
c11d4f6
Level-6
CheahYan Aug 21, 2021
6f0ba24
ui testing
CheahYan Aug 21, 2021
24bb9e5
Level-7
CheahYan Aug 29, 2021
3feae08
Level-7 update
CheahYan Aug 29, 2021
881bfc1
Level-8
CheahYan Aug 29, 2021
b489ae1
Revert "Level-8"
CheahYan Aug 29, 2021
588650b
Merge branch 'branch-Level-7'
CheahYan Aug 29, 2021
cb928b3
Level-8
CheahYan Aug 29, 2021
4c03146
debugging after merge conflicts
CheahYan Aug 29, 2021
ffb8151
OOP
CheahYan Sep 1, 2021
eacfa44
oop updates
CheahYan Sep 3, 2021
77cb385
A-MoreOOP
CheahYan Sep 3, 2021
e48671c
updates
CheahYan Sep 6, 2021
259f0dd
A-JUnit
CheahYan Sep 7, 2021
b4671e3
A-Jar
CheahYan Sep 7, 2021
c06a62d
A-JavaDoc
CheahYan Sep 8, 2021
82a5af5
A-CodingStandard
CheahYan Sep 8, 2021
de2dab3
Level-9
CheahYan Sep 9, 2021
93d8803
Merge branch 'branch-A-JavaDoc'
CheahYan Sep 9, 2021
e7834d4
Merge branch 'branch-Level-9'
CheahYan Sep 9, 2021
d94a1ea
Merge remote-tracking branch 'origin/add-gradle-support'
CheahYan Sep 13, 2021
571b9f1
Gradle and CheckStyle
CheahYan Sep 14, 2021
aa2e2b2
not sure whats going on
CheahYan Sep 14, 2021
9c5ec82
idk
CheahYan Sep 14, 2021
e5bdf9f
idk
CheahYan Sep 14, 2021
860fa28
idk
CheahYan Sep 14, 2021
4315658
idk
CheahYan Sep 14, 2021
f162e12
WHAT IS GOING ON
CheahYan Sep 14, 2021
5bcc063
WHAT IS GOING ON
CheahYan Sep 14, 2021
f0ba15b
WHAT IS GOING ON
CheahYan Sep 14, 2021
fef4323
debugging
CheahYan Sep 14, 2021
7bfa996
Merge branch 'master' of https://github.com/CheahYan/ip
CheahYan Sep 14, 2021
6d9bcae
updates
CheahYan Sep 14, 2021
0e0a9b8
Merge branch 'master' of https://github.com/CheahYan/ip
CheahYan Sep 14, 2021
3aa26c4
updates
CheahYan Sep 14, 2021
b0c8db7
Merge branch 'reset-to-gradle'
CheahYan Sep 14, 2021
4f13f5f
updates
CheahYan Sep 15, 2021
de42740
Level-7 update
CheahYan Sep 16, 2021
d6aa8d4
GUI
CheahYan Sep 20, 2021
dd466c1
debug
CheahYan Sep 20, 2021
53f0877
level 10
CheahYan Sep 20, 2021
36101c6
update
CheahYan Sep 20, 2021
ff4e22b
Update DialogBox.java
CheahYan Sep 20, 2021
b654417
update
CheahYan Sep 20, 2021
f6ce0f9
Add assertions
CheahYan Sep 20, 2021
6c5ee40
Updates to GUI
CheahYan Sep 20, 2021
192813f
Improve Code Quality to all files
CheahYan Sep 22, 2021
4a4d536
Merge branch 'master' into branch-A-Assertions
CheahYan Sep 22, 2021
6cc0fc7
Merge pull request #2 from CheahYan/branch-A-Assertions
CheahYan Sep 22, 2021
e89f694
Merge branch 'master' into branch-A-CodeQuality
CheahYan Sep 22, 2021
afbc471
Merge pull request #3 from CheahYan/branch-A-CodeQuality
CheahYan Sep 22, 2021
e6b2ed4
B-Reminders
CheahYan Sep 22, 2021
0bd4ee1
Add Ui.png and updated MainWindow.fxml
CheahYan Sep 23, 2021
76b4453
Set theme jekyll-theme-cayman
CheahYan Sep 23, 2021
08f7db2
updates to code
CheahYan Sep 23, 2021
394c1c8
Merge branch 'master' of https://github.com/CheahYan/ip
CheahYan Sep 23, 2021
3f2132e
A-UserGuide
CheahYan Sep 23, 2021
24bfe32
more SLAP for Storage
CheahYan Sep 24, 2021
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
6 changes: 6 additions & 0 deletions data/duke.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
todo laundry
deadline return book /by 02/12/2019 1800
event return b ook /at 09/12/2012 1900
done 2
done 2
done 1
10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

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

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

public class Deadline extends Task {

Choose a reason for hiding this comment

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

Perhaps a class should have a header comment to inform users about what the class does. Same suggestion for the other .java files


protected LocalDateTime date;

public Deadline(String description, String date) {

Choose a reason for hiding this comment

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

Perhaps a method could have a header comment to inform users about what the method does.

Same suggestion for the other methods both in this file and other .java files

super(description);

DateTimeFormatter scanned = DateTimeFormatter.ofPattern("dd/MM/yyyy HHmm");
Copy link

Choose a reason for hiding this comment

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

Perhaps a more meaningful name for this variable would be datePattern or dateFormat.

this.date = LocalDateTime.parse(date, scanned);
}

@Override
public String toString() {
DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("dd MMM yyyy hh:mma");
return "[D]" + super.toString() + " (by: " + this.date.format(dateFormat) + ")";
}
}
124 changes: 124 additions & 0 deletions src/main/java/duke/Duke.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package duke;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
import java.util.ArrayList;

public class Duke {

private static final String LOCAL_FILE = "data/duke.txt";

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

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

public void run() {
this.ui.welcome();

Scanner sc = new Scanner(System.in);
Parser parser = new Parser(sc.nextLine());


while (!parser.isBye()) {
try {
if (parser.isList()) {
ui.list(this.tasks);

parser = new Parser(sc.nextLine());
} else if (parser.isDone()) {
try {
this.tasks.done(parser.secondPartInInt());
this.storage.save(parser.getCommand());
ui.done(this.tasks.getMostRecent());

parser = new Parser(sc.nextLine());
} catch (DukeException e) {
ui.showError(e);

parser = new Parser(sc.nextLine());
}
} else if (parser.isToDo()) {
ToDo task;
try {
task = new ToDo(parser.secondPart());
this.tasks.add(task);
this.storage.save(parser.getCommand());
ui.addTask(this.tasks.getMostRecent(), this.tasks);

parser = new Parser(sc.nextLine());
} catch (DukeException e) {
ui.showError(e);

parser = new Parser(sc.nextLine());
}
} else if (parser.isDeadline()) {
Deadline task;
try {
task = new Deadline(parser.deadline()[0], parser.deadline()[1]);
this.tasks.add(task);
this.storage.save(parser.getCommand());
ui.addTask(this.tasks.getMostRecent(), this.tasks);

parser = new Parser(sc.nextLine());
} catch (DukeException e) {
ui.showError(e);

parser = new Parser(sc.nextLine());
}
} else if (parser.isEvent()) {
Event task;
try {
task = new Event(parser.event()[0], parser.event()[1]);
this.tasks.add(task);
this.storage.save(parser.getCommand());
ui.addTask(this.tasks.getMostRecent(), this.tasks);

parser = new Parser(sc.nextLine());
} catch (DukeException e) {
ui.showError(e);

parser = new Parser(sc.nextLine());
}
} else if (parser.isDelete()) {
try {
this.tasks.delete(parser.secondPartInInt());
ui.deleteTask(this.tasks.getMostRecent(), this.tasks);

parser = new Parser(sc.nextLine());
} catch (DukeException e) {
ui.showError(e);

parser = new Parser(sc.nextLine());
}
} else {
throw new DukeException("I do not know what you want to do!");
}
} catch (DukeException e) {
ui.showError(e);

parser = new Parser(sc.nextLine());
}
}

ui.bye();
sc.close();
}

public static void main(String[] args) {
new Duke(LOCAL_FILE).run();

}
}
Copy link

Choose a reason for hiding this comment

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

Perhaps you could apply more OOP by extracting out closely related code as classes, rather than letting the Main method handle everything.

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

public class DukeException extends Exception {

Choose a reason for hiding this comment

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

Great work using inheritance! LGTM!


protected String errorMessage;

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

@Override
public String toString() {
return ":(( sorry bud but " + this.errorMessage;
}
}
23 changes: 23 additions & 0 deletions src/main/java/duke/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package duke;

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

public class Event extends Task {

protected LocalDateTime date;


public Event(String description, String date) {
super(description);

DateTimeFormatter scanned = DateTimeFormatter.ofPattern("dd/MM/yyyy HHmm");
this.date = LocalDateTime.parse(date, scanned);
}

@Override
public String toString() {
DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("dd MMM yyyy hh:mma");
return "[E]" + super.toString() + " (at: " + this.date.format(dateFormat) + ")";
}
}
104 changes: 104 additions & 0 deletions src/main/java/duke/Parser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package duke;

public class Parser {
private String command;
private String[] twoPart;
private String[] time;

public Parser(String command) {
this.command = command;
this.twoPart = this.command.split(" ", 2);
}

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

public String firstPart() {
return this.twoPart[0];
}

public int secondPartInInt() throws DukeException {

Choose a reason for hiding this comment

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

Method names should be verbs. So this would be better named as 'getSecondPartInInt'.

try {
return Integer.valueOf(this.twoPart[1]);
} catch (ArrayIndexOutOfBoundsException e) {
throw new DukeException("which specific task from the list? Give a number!");
}
}

public String secondPart() throws DukeException {
try {
return this.twoPart[1];
} catch (ArrayIndexOutOfBoundsException error) {
throw new DukeException("do remember to add your description!");
}
}

public String[] deadline() {
return this.twoPart[1].split(" /by ", 2);
}

public String[] event() {
return this.twoPart[1].split(" /at ", 2);
}

public String[] parse() {
return this.twoPart;
}

public boolean isBye() {

Choose a reason for hiding this comment

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

I guess u can shorten this into one-liner by just returning 'this.command.equals("bye"')'. Helps improve readability somewhat but I guess I'm just nitpicking here.

if (this.command.equals("bye")) {
return true;
} else {
return false;
}
}

public boolean isList() {
if (this.command.equals("list")) {
return true;
} else {
return false;
}
}

public boolean isDone() {
if (this.twoPart[0].equals("done")) {
return true;
} else {
return false;
}
}

public boolean isToDo() {
if (this.twoPart[0].equals("todo")) {
return true;
} else {
return false;
}
}

public boolean isDeadline() {
if (this.twoPart[0].equals("deadline")) {
return true;
} else {
return false;
}
}

public boolean isEvent() {
if (this.twoPart[0].equals("event")) {
return true;
} else {
return false;
}
}

public boolean isDelete() {
if (this.twoPart[0].equals("delete")) {
return true;
} else {
return false;
}
}
}
69 changes: 69 additions & 0 deletions src/main/java/duke/Storage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package duke;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

public class Storage {
private File storage;
private String fileName;

public Storage(String fileName) {
this.fileName = fileName;
this.storage = new File(fileName);
}

public TaskList load() throws DukeException {
try {
this.storage.createNewFile();
} catch (IOException error) {
throw new DukeException("ensure you have created a folder named 'data' within the main project directory!");
}
try {
Scanner fileScanner = new Scanner(this.storage);
TaskList tasklist = new TaskList();

while (fileScanner.hasNext()) {
String fileData = fileScanner.nextLine();
Parser parser = new Parser(fileData);

if (parser.isDone()) {
tasklist.done(parser.secondPartInInt());
} else if (parser.isToDo()) {
ToDo task = new ToDo(parser.secondPart());
tasklist.add(task);
} else if (parser.isDeadline()) {
Deadline task = new Deadline(parser.deadline()[0], parser.deadline()[1]);
tasklist.add(task);
} else if (parser.isEvent()) {
Event task = new Event(parser.event()[0], parser.event()[1]);
tasklist.add(task);
} else if (parser.isDelete()) {
tasklist.delete(parser.secondPartInInt());
}
}

return tasklist;
} catch (FileNotFoundException e) {
throw new DukeException("ensure you have created a folder named 'data' within the main project directory!");
}

//load contents into TaskList
}

private void appendToFile(String textToAppend) throws IOException {
FileWriter fw = new FileWriter(this.fileName, true); // create a FileWriter in append mode
fw.write(textToAppend);
fw.close();
}

public void save(String history) throws DukeException{
try {
appendToFile(history + System.lineSeparator());
} catch (IOException e) {
throw new DukeException(e.getMessage());
}
}
}
Loading