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 14 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
4 changes: 4 additions & 0 deletions data/duke.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
todo laundry
deadline return book /by 02/12/2019 1800
event return b ook /at 09/12/2012 1900
done 2
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) + ")";
}
}
213 changes: 213 additions & 0 deletions src/main/java/duke/Duke.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
package duke;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.sql.SQLOutput;
import java.util.Scanner;
import java.util.ArrayList;

public class Duke {

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

public static void appendToFile(String filePath, String textToAppend) throws IOException {
FileWriter fw = new FileWriter(filePath, true); // create a FileWriter in append mode

Choose a reason for hiding this comment

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

leaving comments to help readers enables a better understanding of your code and might even help to hasten the onboarding process. Good job!

fw.write(textToAppend);
fw.close();
}


public static void main(String[] args) {

String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
System.out.println("What can I do for you?");

Scanner sc = new Scanner(System.in);
String a = sc.nextLine();
String[] b = a.split(" ", 2);
Copy link

Choose a reason for hiding this comment

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

Perhaps it would be good if you could avoid using single letters to name variables unless they are iterator variables. I noticed this issue in other parts too.


ArrayList<Task> history = new ArrayList<>();

File importedFile = new File(LOCAL_FILE);

try {
importedFile.createNewFile();
} catch (IOException error) {
System.out.println("Ensure you have created a folder named 'data' within the main project directory!");
}

try {
Scanner fileScanner = new Scanner(importedFile);
while (fileScanner.hasNext()) {
String fileData = fileScanner.nextLine();
String[] details = fileData.split(" ", 2);

if (details[0].equals("done")) {
int taskIndex = Integer.valueOf(details[1]);
Task completedTask = history.get(taskIndex - 1);
completedTask.Done();

} else if (details[0].equals("todo")) {
ToDo task = new ToDo(details[1]);
history.add(task);

} else if (details[0].equals("deadline")) {
String[] c = details[1].split(" /by ", 2);
Deadline task = new Deadline(c[0], c[1]);
history.add(task);

} else if (details[0].equals("event")) {
String[] c = details[1].split(" /at ", 2);
Event task = new Event(c[0], c[1]);
history.add(task);

} else if (details[0].equals("delete")) {
int taskIndex = Integer.valueOf(details[1]);
Task removed = history.get(taskIndex - 1);
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 would be removedTask to indicate that this is the task that had been removed.


history.remove(taskIndex - 1);
}
}
} catch (FileNotFoundException e) {
System.out.println("Something went wrong: " + e.getMessage());
}


while (!a.equals("bye")) {
try {
if (a.equals("list")) {
System.out.println("Here are the tasks in your list:");

int length = history.size();
for (int i = 0; i < length; i++) {
System.out.println(String.valueOf(i + 1) + ". " + history.get(i));
}
a = sc.nextLine();
b = a.split(" ", 2);

} else if (b[0].equals("done")) {
try {
int taskIndex = Integer.valueOf(b[1]);
Task completedTask = history.get(taskIndex - 1);
completedTask.Done();
System.out.println("Nice! I have marked this task as done!");
System.out.println(completedTask);

try {
appendToFile(LOCAL_FILE, a + System.lineSeparator());
} catch (IOException e) {
System.out.println("Something went wrong: " + e.getMessage());
}

a = sc.nextLine();
b = a.split(" ", 2);
} catch (ArrayIndexOutOfBoundsException error) {
System.out.println(":(( sorry bud but which specific task is done?");

a = sc.nextLine();
b = a.split(" ", 2);
}
} else if (b[0].equals("todo")) {
try {
ToDo task = new ToDo(b[1]);
history.add(task);
int length = history.size();

System.out.println("Added task:");
System.out.println(task);
System.out.println("You have " + length + " tasks in the list");

try {
appendToFile(LOCAL_FILE, a + System.lineSeparator());
} catch (IOException e) {
System.out.println("Something went wrong: " + e.getMessage());
}

a = sc.nextLine();
b = a.split(" ", 2);
} catch (ArrayIndexOutOfBoundsException error) {
System.out.println(":(( sorry bud but the description of your todo cannot be empty!");

a = sc.nextLine();
b = a.split(" ", 2);
}
} else if (b[0].equals("deadline")) {
String[] c = b[1].split(" /by ", 2);
Deadline task = new Deadline(c[0], c[1]);
history.add(task);
int length = history.size();

System.out.println("Added task:");
System.out.println(task);
System.out.println("You have " + String.valueOf(length) + " tasks in the list");

try {
appendToFile(LOCAL_FILE, a + System.lineSeparator());
} catch (IOException e) {
System.out.println("Something went wrong: " + e.getMessage());
}

a = sc.nextLine();
b = a.split(" ", 2);

} else if (b[0].equals("event")) {
String[] c = b[1].split(" /at ", 2);
Event task = new Event(c[0], c[1]);
history.add(task);
int length = history.size();

System.out.println("Added task:");
System.out.println(task);
System.out.println("You have " + String.valueOf(length) + " tasks in the list");

try {
appendToFile(LOCAL_FILE, a + System.lineSeparator());
} catch (IOException e) {
System.out.println("Something went wrong: " + e.getMessage());
}

a = sc.nextLine();
b = a.split(" ", 2);
} else if (b[0].equals("delete")) {
int taskIndex = Integer.valueOf(b[1]);
Task removed = history.get(taskIndex - 1);

history.remove(taskIndex - 1);
int length = history.size();

System.out.println("Ok! I have removed this task:");
System.out.println(removed);
System.out.println("Now you have " + String.valueOf(length) + " tasks in the list.");

try {
appendToFile(LOCAL_FILE, a + System.lineSeparator());
} catch (IOException e) {
System.out.println("Something went wrong: " + e.getMessage());
}

a = sc.nextLine();
b = a.split(" ", 2);
} else {
throw new DukeException("I do not know what you want to do!");
}
} catch (DukeException error) {
System.out.println(error);

a = sc.nextLine();
b = a.split(" ", 2);
}
}
System.out.println("Bye! Hope to see you again soon!");
sc.close();

}
}
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) + ")";
}
}
28 changes: 28 additions & 0 deletions src/main/java/duke/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package duke;

public class Task {
protected String description;
protected boolean isDone;

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

public String convertToFile() {

Choose a reason for hiding this comment

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

Great use of naming conventions!

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 suitable name is getDescription. I feel that naming it convertToFile can be misleading since this method does not handle any conversion.

return this.description;
}

public String getStatusIcon() {
return (isDone ? "X" : " ");
}

public void Done() {

Choose a reason for hiding this comment

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

Method names should be in camel case.

this.isDone = true;
}

@Override
public String toString() {
return "[" + getStatusIcon() + "] " + this.description;
}
}
13 changes: 13 additions & 0 deletions src/main/java/duke/ToDo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package duke;

public class ToDo extends Task {

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

@Override
public String toString() {
return "[T]" + super.toString();
}
}
1 change: 1 addition & 0 deletions text-ui-test/EXPECTED.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ Hello from
| |_| | |_| | < __/
|____/ \__,_|_|\_\___|

What can I do for you?