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

[Singh Abdullah Alexander] iP #519

Open
wants to merge 58 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
556af3f
Add Gradle support
May 24, 2020
df365b5
Completed Level-1
alexandermula Aug 25, 2022
1346cd5
added list
alexandermula Aug 25, 2022
35f557b
Added mark as done
alexandermula Aug 25, 2022
1427298
ToDos, Events and Deadlines
alexandermula Aug 25, 2022
924806e
Text testing
alexandermula Aug 25, 2022
7a099dd
error handling
alexandermula Aug 25, 2022
23228eb
Implemented delete
alexandermula Aug 25, 2022
79c8c7b
Added file read function (to refine save function later)
alexandermula Sep 1, 2022
a9e73ff
Store dates as date object
alexandermula Sep 1, 2022
c267e54
Merge branch 'branch-Level-8'
alexandermula Sep 1, 2022
08cf255
Organise classes into suitable packages
alexandermula Sep 3, 2022
917c4da
abstract read user input to ui class
alexandermula Sep 3, 2022
dafa0e1
add list command
alexandermula Sep 3, 2022
ab17e07
add unmark command
alexandermula Sep 3, 2022
ee3871e
add all commands
alexandermula Sep 3, 2022
2b04497
add parser logic
alexandermula Sep 3, 2022
c453a9a
fix parser logic
alexandermula Sep 3, 2022
0770b6e
add TaskList class
alexandermula Sep 3, 2022
8e27eb5
add ui logic
alexandermula Sep 3, 2022
d930758
fix storage logic
alexandermula Sep 4, 2022
ddbd5f6
clean up packages
alexandermula Sep 4, 2022
36fb04e
Merge branch 'nus-cs2103-AY2223S1:add-gradle-support' into add-gradle…
alexandermula Sep 4, 2022
b055c54
add gradle support
alexandermula Sep 4, 2022
c225250
add junit tests
alexandermula Sep 4, 2022
d2722ef
Add javadocs for TaskList
alexandermula Sep 8, 2022
d88c342
Add javadocs to all classes
alexandermula Sep 8, 2022
a5e7b67
Fix code to comply with coding standard
alexandermula Sep 8, 2022
56ab4d6
Add find function
alexandermula Sep 8, 2022
dfc760d
Merge branch 'branch-A-CodingStandard'
alexandermula Sep 8, 2022
59bf323
Merge branch 'branch-Level-9'
alexandermula Sep 8, 2022
4da3212
Add checkstyle
alexandermula Sep 8, 2022
fd0c357
Add view and image resources
alexandermula Sep 8, 2022
692246c
Add javafx
alexandermula Sep 8, 2022
4cfda08
add javaFX
alexandermula Sep 14, 2022
2bfa59e
add assert statements
alexandermula Sep 14, 2022
0567cc5
Merge pull request #2 from alexandermula/branch-A-Assertions
alexandermula Sep 14, 2022
e386799
fix code quality
alexandermula Sep 14, 2022
b668147
Merge pull request #3 from alexandermula/branch-A-CodeQuality
alexandermula Sep 14, 2022
c46ee09
Add sort command
alexandermula Sep 15, 2022
0f7a2fe
Merge pull request #4 from alexandermula/branch-C-Sort
alexandermula Sep 15, 2022
1c5c16d
Find command: add varargs to pass multiple keywords
alexandermula Sep 15, 2022
9c75ccf
Merge branch 'master' of https://github.com/alexandermula/ip
alexandermula Sep 15, 2022
bbf40fc
Merge pull request #5 from alexandermula/branch-C-Sort
alexandermula Sep 15, 2022
19c3253
Merge branch 'master' of https://github.com/alexandermula/ip
alexandermula Sep 15, 2022
ce78d08
Add enums
alexandermula Sep 15, 2022
01a6f58
Add styling to GUI
alexandermula Sep 15, 2022
ddd0c10
Add personality
alexandermula Sep 15, 2022
a0be07b
Add github page
alexandermula Sep 15, 2022
81eec33
Build jar file
alexandermula Sep 15, 2022
9de9aa0
Replace tabs usage with spaces
alexandermula Oct 16, 2022
723befa
Fix header comments
alexandermula Oct 16, 2022
59e259f
Remove dead code
alexandermula Oct 16, 2022
2bf9003
Fix package name style
alexandermula Oct 16, 2022
36401c4
Add test cases
alexandermula Oct 16, 2022
8619248
Fix header comments
alexandermula Oct 16, 2022
4562947
Fix code quality
alexandermula Oct 16, 2022
ee1e14a
Fix code quality
alexandermula Oct 16, 2022
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
103 changes: 103 additions & 0 deletions src/main/java/Chacha.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import java.util.Scanner;
import java.util.ArrayList;
import java.io.File;
import java.io.FileNotFoundException;

public class Chacha {
public static void main(String[] args) {
System.out.println("Hello! I'm Chacha\n" + "What can I do for you?");
Scanner input = new Scanner(System.in);
String s = input.nextLine();

Choose a reason for hiding this comment

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

Maybe can name s differently? To a clearer variable

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

Choose a reason for hiding this comment

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

Good that the variable names are in camel case

Copy link

Choose a reason for hiding this comment

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

Can consider making taskList a private static final field in the class

while (!s.equals("bye")) {
if (s.equals("list")) {
for (int i = 0; i < taskList.size();i++) {
Task t = taskList.get(i);
System.out.println(i + 1 +
"." +
t.toString());
}

} else if (s.contains("unmark")) {
Copy link

Choose a reason for hiding this comment

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

Can consider using s.startsWith function to check if the task type is indeed the first input


String[] split = s.split("\\s+");
Task task = taskList.get(Integer.valueOf(split[1]) - 1);
task.unmarkAsDone();
System.out.println("OK, I've marked this task as not done yet:\n" + task.toString());

} else if (s.contains("mark")) {
String[] split = s.split("\\s+");
Task task = taskList.get(Integer.valueOf(split[1]) - 1);
task.markAsDone();
System.out.println("Nice! I've marked this task as done:\n" + task.toString());

} else if (s.contains("delete")) {
String[] split = s.split("\\s+");
Task task = taskList.get(Integer.valueOf(split[1]) - 1);
System.out.println("Noted. I've removed this task:");
System.out.println(task.toString());
taskList.remove(Integer.valueOf(split[1]) - 1);
System.out.println("Now you have " + taskList.size() + " tasks in the list.");

} else if (s.contains("deadline")) {
try {
String date = s.substring(s.indexOf("/by ") + 4);
date.trim();
String description = s.substring(0,s.indexOf("/"));
description = description.substring(s.indexOf("deadline ") + 9);
description.trim();
Deadline deadline = new Deadline(description, date);
taskList.add(deadline);
System.out.println("Got it. I've added this task:");
System.out.println(deadline.toString());
System.out.println("Now you have " + taskList.size() + " tasks in the list.");
} catch(Exception e) {
System.out.println("OOPS!!! The description of a deadline cannot be empty.");
}
} else if (s.contains("todo")) {
try {
String description = s.substring(s.indexOf("todo ") + 5);
System.out.println("heree");
description.trim();
Todo todo = new Todo(description);
taskList.add(todo);
System.out.println("Got it. I've added this task:");
System.out.println(todo.toString());
System.out.println("Now you have " + taskList.size() + " tasks in the list.");
} catch(Exception e) {
System.out.println("OOPS!!! The description of a todo cannot be empty.");
}

} else if (s.contains("event")) {
try {
String range = s.substring(s.indexOf("/at ") + 4);
range.trim();
String description = s.substring(0,s.indexOf("/"));
description = description.substring(s.indexOf("event ") + 6);
description.trim();
Event event = new Event(description, range);
taskList.add(event);
System.out.println("Got it. I've added this task:");
System.out.println(event.toString());
System.out.println("Now you have " + taskList.size() + " tasks in the list.");
} catch(Exception e) {
System.out.println("OOPS!!! The description of a event cannot be empty.");
}
} else {
System.out.println("OOPS!!! I'm sorry, but I don't know what that means :-(");
}
s = input.nextLine();
}
System.out.println("Bye. Hope to see you again soon!");
input.close();
}

private static void loadData(String filePath) throws FileNotFoundException {
File f = new File(filePath); // create a File for the given file path
Scanner s = new Scanner(f); // create a Scanner using the File as the source
while (s.hasNext()) {
//load task objects into array
System.out.println(s.nextLine());
}
}
Copy link

Choose a reason for hiding this comment

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

Overall code looks clean and should have no problem finishing up the ip

}
48 changes: 48 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import java.text.DateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;

public class Deadline extends Task {
private String description;
private LocalDate date;
private boolean isDone;

Choose a reason for hiding this comment

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

Good naming of booleans:)

private String type;

public Deadline(String description, String date) {
this.description = description;
this.date = LocalDate.parse(date);
this.type = "D";
}

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

public void unmarkAsDone() {
this.isDone = false;
}

public String getStatusIcon() {
return (isDone ? "X" : " "); // mark done task with X
}

public String getDescription() {
return description;
}

public String getType() {
return type;
}

public String getDate() {
String formattedDate = date.format(DateTimeFormatter.ofPattern("MMM d yyyy"));
return formattedDate;
}

@Override
public String toString() {
return "[" + type + "]" + "[" + getStatusIcon() + "] " + description + "(by: " + getDate() + ")";
}

}
10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

48 changes: 48 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import java.text.DateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;

public class Event extends Task {
private String description;
private LocalDate range;
private boolean isDone;
private String type;

public Event(String description, String range) {
this.description = description;
this.range = LocalDate.parse(range);
this.type = "E";
}

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

public void unmarkAsDone() {
this.isDone = false;
}

public String getStatusIcon() {
return (isDone ? "X" : " "); // mark done task with X
}

public String getDescription() {
return description;
}

public String getType() {
return type;
}

public String getDate() {
String formattedDate = range.format(DateTimeFormatter.ofPattern("MMM d yyyy"));
return formattedDate;
}

@Override
public String toString() {
return "[" + type + "]" + "[" + getStatusIcon() + "] " + description + "(at: " + getDate() + ")";
}

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

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

public Task() {
}

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

public void unmarkAsDone() {
this.isDone = false;
}

public String getStatusIcon() {
return (isDone ? "X" : " "); // mark done task with X
}

public String getDescription() {
return description;
}

}
36 changes: 36 additions & 0 deletions src/main/java/Todo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
public class Todo extends Task {
private String description;
private boolean isDone;
private String type;

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

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

public void unmarkAsDone() {
this.isDone = false;
}

public String getStatusIcon() {
return (isDone ? "X" : " "); // mark done task with X
}

public String getDescription() {
return description;
}

public String getType() {
return type;
}

@Override
public String toString() {
return "[" + type + "]" + "[" + getStatusIcon() + "] " + description;
}

}
23 changes: 16 additions & 7 deletions text-ui-test/EXPECTED.TXT
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
Hello from
____ _
| _ \ _ _| | _____
| | | | | | | |/ / _ \
| |_| | |_| | < __/
|____/ \__,_|_|\_\___|

Hello! I'm Chacha
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][ ] project meeting (at: Mon 2-4pm)
Now you have 3 tasks in the list.
Nice! I've marked this task as done:
[D][X] return book (by: Sunday)
1.[T][ ] borrow book
2.[D][X] return book (by: Sunday)
3.[E][ ] project meeting (at: Mon 2-4pm)
5 changes: 5 additions & 0 deletions text-ui-test/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
todo borrow book
deadline return book /by Sunday
event project meeting /at Mon 2-4pm
mark 2
list
4 changes: 2 additions & 2 deletions text-ui-test/runtest.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ REM delete output from previous run
if exist ACTUAL.TXT del ACTUAL.TXT

REM compile the code into the bin folder
javac -cp ..\src\main\java -Xlint:none -d ..\bin ..\src\main\java\*.java
javac -cp ..\src\main\java\Chacha.java -Xlint:none -d ..\bin ..\src\main\java\*.java
IF ERRORLEVEL 1 (
echo ********** BUILD FAILURE **********
exit /b 1
)
REM no error here, errorlevel == 0

REM run the program, feed commands from input.txt file and redirect the output to the ACTUAL.TXT
java -classpath ..\bin Duke < input.txt > ACTUAL.TXT
java -classpath ..\bin Chacha < input.txt > ACTUAL.TXT

REM compare the output to the expected output
FC ACTUAL.TXT EXPECTED.TXT