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

[Lulu Y] iP #473

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
d839859
Add Gradle support
May 24, 2020
661654c
Greet, Echo, and Exit
luluyousef Aug 19, 2021
b0037be
Add and List
luluyousef Aug 19, 2021
8c89dc5
Added ability to mark tasks as done.
luluyousef Aug 19, 2021
fad94ab
Added support for tracking todo, deadlines, and events
luluyousef Aug 19, 2021
cf8150a
Automated Text UI Testing
luluyousef Aug 21, 2021
d66b802
Handled user input errors
luluyousef Aug 21, 2021
7b3a3ea
Added deleting task from the list.
luluyousef Aug 21, 2021
1385ef2
Complete level 7.
luluyousef Aug 26, 2021
0b59ceb
Level 8
luluyousef Aug 28, 2021
8a580c2
Use More OOP
luluyousef Sep 4, 2021
3658c71
Organize into package duke
luluyousef Sep 4, 2021
aace4c9
Add JUnit tests
luluyousef Sep 5, 2021
a0d5982
Package app as a JAR file
luluyousef Sep 5, 2021
96f9d69
Add JavaDoc comments
luluyousef Sep 5, 2021
2b3acec
Tweak Code to comply with coding standard
luluyousef Sep 5, 2021
d00efa7
Implement Level 9
luluyousef Sep 5, 2021
ee836cd
Task file
luluyousef Sep 5, 2021
70f9441
tasks
luluyousef Sep 5, 2021
dd6bf47
Merge branch 'branch-A-JavaDoc'
luluyousef Sep 5, 2021
e2eb3f8
Merge remote-tracking branch 'origin/add-gradle-support'
luluyousef Sep 6, 2021
a0ab049
Automate project builds using Gradle
luluyousef Sep 6, 2021
18b246f
Use Checkstyle
luluyousef Sep 6, 2021
53e21c5
Add a GUI to Duke.
luluyousef Sep 14, 2021
d7cf635
The code does not have any assertions.
luluyousef Sep 19, 2021
06ed319
Merge pull request #2 from luluyousef/branch-A-Assertion
luluyousef Sep 20, 2021
c371ad6
Merge branch 'master' of https://github.com/luluyousef/ip
luluyousef Sep 20, 2021
056aa5d
Some methods in the code are too long in the Parser and Storage class.
luluyousef Sep 20, 2021
7a673ec
Merge pull request #3 from luluyousef/branch-A-CodeQuality
luluyousef Sep 20, 2021
4795a70
Merge branch 'master' of https://github.com/luluyousef/ip
luluyousef Sep 20, 2021
eae433b
Improve the GUI
luluyousef Sep 20, 2021
4a41bc0
Add C-Sort extension and fix loading issue in the Storage class
luluyousef Sep 21, 2021
9e1f4e2
Add a User Guide to the Project
luluyousef Sep 21, 2021
2b25d9b
Add Ui Image
luluyousef Sep 21, 2021
2f4be6b
Fix User Guide
luluyousef Sep 21, 2021
eaf0b08
no message
luluyousef Sep 21, 2021
6268a75
Fix DeleteCommand and Finalize Project
luluyousef Sep 21, 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
Binary file added src/main/java/Deadline.class
Binary file not shown.
18 changes: 18 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class Deadline extends Task{
Copy link

Choose a reason for hiding this comment

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

Could perhaps add header docs to the class!

protected LocalDate time;

public Deadline(String description, String by) {
super(description);
this.label = "D";
time = LocalDate.parse(by);
}

@Override
public String toString() {
return "[D]" + super.toString() + " (by: " + time.format(DateTimeFormatter.ofPattern("MMM d yyyy")) + ")";
}
}
Binary file added src/main/java/Duke.class
Binary file not shown.
176 changes: 169 additions & 7 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,172 @@
import java.util.ArrayList;
import java.util.Scanner;
import java.io.FileWriter;
import java.io.File;
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);

public static void main(String[] args) throws DukeException, IOException{
String pathName = "./data/duke.txt";
File f = new File(pathName);
try {
if(!f.exists()){
f.createNewFile();
}
Scanner sc = new Scanner(f);
ArrayList<Task> t = new ArrayList<>();

Choose a reason for hiding this comment

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

I am not sure I like the name of the ArrayList. I think giving it a clearer name would improve the readability of your code. For example, 'taskList'.

while (sc.hasNext()) {
String task = sc.nextLine();
String[] taskArr = task.split("//|");
if (taskArr[0].equals("T")) {
Todo td = new Todo(taskArr[2]);
if (taskArr[1].equals("1")) {
td.markAsDone();
}
t.add(td);
}
if (taskArr[0].equals("D")) {
Deadline d = new Deadline(taskArr[2], taskArr[3]);
if (taskArr[1].equals("1")) {
d.markAsDone();
}
t.add(d);
}
if (taskArr[0].equals("E")) {
Event e = new Event(taskArr[2], taskArr[3]);
if (taskArr[1].equals("1")) {
e.markAsDone();
}
t.add(e);
}
}
int ctr = 0;
Scanner scanner = new Scanner(System.in);
System.out.println("_______________________________________________");
Copy link

Choose a reason for hiding this comment

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

Can perhaps use a function to print the dividers to make the code look more readable!

System.out.println("Hello! I'm Duke\n" + "What can I do for you?");

Choose a reason for hiding this comment

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

I think placing a line break before the '+' would improve improve the readability of your code. This is because you add a next line character before the '+', so presenting your code in the same way the output will look would be nice.

System.out.println("_______________________________________________");

while (scanner.hasNext()) {
try {
String response = scanner.nextLine();
if (response.equals("list")) {
System.out.println("_______________________________________________");
System.out.println("Here are the tasks on your list: ");
for (int i = 0; i < ctr; i++) {
System.out.println((i + 1) + ". " + t.get(i));
}
System.out.println("_______________________________________________");
} else if (response.equals("bye")) {
System.out.println("_______________________________________________");
System.out.println("Bye! Hope to see you again soon!");
System.out.println("_______________________________________________");
writeFile(f, t);
System.exit(0);
} else if (response.contains("done")) {
String[] str = response.split(" ");
String task = str[0];
int num = Integer.parseInt(str[1]);
t.get(num - 1).markAsDone();

System.out.println("Nice! I've marked this task as done: \n" + t.get(num - 1).toString());
System.out.println("_______________________________________________");
} else if (response.contains("todo")) {
if (response.length() > 4) {
String[] str = response.split(" ");
String task = str[0];
String command = str[1];
command = response.substring(response.indexOf(" ") + 1);
Task td = new Todo(command);
t.add(td);

System.out.println("Got it! I've added this task: \n" + td.toString());
ctr++;
System.out.println("Now you have " + ctr + " tasks in the list.");
System.out.println("_______________________________________________");
} else {
throw new DukeException("☹ OOPS!!! The description of a todo cannot be empty.");
}
} else if (response.contains("deadline")) {
int tLabelFirst = response.indexOf(" ") + 1;
int tTimeFirst = response.indexOf("/");
String tLabel = response.substring(tLabelFirst, tTimeFirst - 1);
String tTime = response.substring(tTimeFirst + 4);
Task td = new Deadline(tLabel, tTime);
t.add(td);

System.out.println("Got it! I've added this task: \n" + td.toString());
ctr++;
System.out.println("Now you have " + ctr + " tasks in the list.");
System.out.println("_______________________________________________");
} else if (response.contains("event")) {
int tLabelFirst = response.indexOf(" ") + 1;
int tTimeFirst = response.indexOf("/");
String tLabel = response.substring(tLabelFirst, tTimeFirst - 1);
String tTime = response.substring(tTimeFirst + 4);
Task td = new Event(tLabel, tTime);
t.add(td);

System.out.println("Got it! I've added this task: \n" + td.toString());
ctr++;
System.out.println("Now you have " + ctr + " tasks in the list.");
System.out.println("_______________________________________________");
} else if (response.contains("delete")) {
String[] str = response.split(" ");
String task = str[0];
int num = Integer.parseInt(str[1]);
Task tsk = t.remove(num - 1);

System.out.println("Noted. I've now removed this task: \n" + tsk);
ctr--;
System.out.println("Now you have " + ctr + " tasks in the list.");
System.out.println("_______________________________________________");
} else {
throw new DukeException("☹ OOPS!!! I'm sorry, but I don't know what that means :-( " +
"Try todo, event, or deadline");
}
} catch (DukeException d) {
System.out.println(d.getMessage());
}
}
}catch(IOException e){

Choose a reason for hiding this comment

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

I think you may have missed this. Add a space between the } and catch.

System.out.println("OOPS!!! Directory not found. " + e.getMessage());
System.exit(0);
}
}
public static void writeFile(File f, ArrayList<Task> tasks) throws IOException {
FileWriter fw = new FileWriter(f);
for(int i = 0; i < tasks.size(); i++){
Task t = tasks.get(i);
String text = "";
if(t.label.equals("T")){
text = text.concat("T|");
if(t.isDone){
text = text.concat("1|");
}else{
text = text.concat("0|");
}
text = text.concat(t.description + "\n");
}
if(t.label.equals("D")){
text = text.concat("D|");
if(t.isDone){
text = text.concat("1|");
}else{
text = text.concat("0|");
}
text = text.concat(t.description + "|" + ((Deadline) t).time + "\n");
}
if(t.label.equals("E")){
text = text.concat("E|");
if(t.isDone){
text = text.concat("1|");
}else{
text = text.concat("0|");
}
text = text.concat(t.description + "|" + ((Event) t).by + "\n");
}

Choose a reason for hiding this comment

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

I think it is better to add a space around every 'if', 'else' and 'for' as this helps the readability of your code.

fw.write(text);
}
fw.close();
}
}
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{

Choose a reason for hiding this comment

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

I think you should add a space after Exception. I noticed that this is a recurring practice for your classes. Adding a space between the class declaration and the { will help to add readability to your code. I suggest you read the part on "White space within a statement" in the Java coding standard 😄 .

public DukeException(String message){
super(message);
}
}
Binary file added src/main/java/Event.class
Binary file not shown.
15 changes: 15 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
public class Event extends Task{

protected String by;

Choose a reason for hiding this comment

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

I think it would be better to keep your class variables as private. Do you have a reason to declare them as protected?


public Event(String description, String by) {
super(description);
this.label = "E";
this.by = by;
}

@Override
public String toString() {
return "[E]" + super.toString() + " (by: " + by + ")";
}
}
Binary file added src/main/java/Task.class
Binary file not shown.
20 changes: 20 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
public class Task {
protected String description;
protected boolean isDone;
String label;

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

public String getStatusIcon() {
return (isDone ? "X" : " "); // mark done task with X
}
public void markAsDone(){
this.isDone = true;
}
public String toString(){
return "[" + getStatusIcon() +"] " + this.description;
}
}
Binary file added src/main/java/Todo.class
Binary file not shown.
14 changes: 14 additions & 0 deletions src/main/java/Todo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public class Todo extends Task {

protected String by;

public Todo(String description) {
super(description);
this.label = "T";
}

@Override
public String toString() {
return "[T]" + super.toString();
}
}
63 changes: 56 additions & 7 deletions text-ui-test/EXPECTED.TXT
Original file line number Diff line number Diff line change
@@ -1,7 +1,56 @@
Hello from
____ _
| _ \ _ _| | _____
| | | | | | | |/ / _ \
| |_| | |_| | < __/
|____/ \__,_|_|\_\___|

_______________________________________________
Hello! I'm Duke
What can I do for you?
_______________________________________________
Got it! I've added this task:
[T][ ] read book
Now you have 1 tasks in the list.
_______________________________________________
Got it! I've added this task:
[T][ ] cook dinner
Now you have 2 tasks in the list.
_______________________________________________
_______________________________________________
Here are the tasks on your list:
1. [T][ ] read book
2. [T][ ] cook dinner
_______________________________________________
Got it! I've added this task:
[D][ ] CS2105 assignment (by: Tuesday)
Now you have 3 tasks in the list.
_______________________________________________
Got it! I've added this task:
[D][ ] CS2103T task (by: Today)
Now you have 4 tasks in the list.
_______________________________________________
Nice! I've marked this task as done:
[T][X] read book
_______________________________________________
_______________________________________________
Here are the tasks on your list:
1. [T][X] read book
2. [T][ ] cook dinner
3. [D][ ] CS2105 assignment (by: Tuesday)
4. [D][ ] CS2103T task (by: Today)
_______________________________________________
Got it! I've added this task:
[E][ ] archery course (by: Aug 26 5-7 pm)
Now you have 5 tasks in the list.
_______________________________________________
Nice! I've marked this task as done:
[D][X] CS2105 assignment (by: Tuesday)
_______________________________________________
Nice! I've marked this task as done:
[D][X] CS2103T task (by: Today)
_______________________________________________
_______________________________________________
Here are the tasks on your list:
1. [T][X] read book
2. [T][ ] cook dinner
3. [D][X] CS2105 assignment (by: Tuesday)
4. [D][X] CS2103T task (by: Today)
5. [E][ ] archery course (by: Aug 26 5-7 pm)
_______________________________________________
_______________________________________________
Bye! Hope to see you again soon!
_______________________________________________
12 changes: 12 additions & 0 deletions text-ui-test/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
todo read book
todo cook dinner
list
deadline CS2105 assignment /by Tuesday
deadline CS2103T task /by Today
done 1
list
event archery course /at Aug 26 5-7 pm
done 3
done 4
list
bye