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

Alex Setyawan iP #476

Open
wants to merge 53 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
55f9f9f
docs/README.md: Tweak document template
Jan 7, 2024
f837ddb
Add Gradle support
May 24, 2020
a6f7324
Bump gradle and lib version
Eclipse-Dominator Aug 5, 2023
fbeec99
started level 0
alex-setyawan Jan 27, 2024
95ae554
added level 1
alex-setyawan Jan 27, 2024
dcaa40e
added level 2
alex-setyawan Jan 27, 2024
8282fc9
added level 3
alex-setyawan Jan 27, 2024
23725d6
added level 4
alex-setyawan Jan 27, 2024
0c94cc6
added text UI testing
alex-setyawan Jan 31, 2024
d9be119
added level 5
alex-setyawan Jan 31, 2024
40c2f1c
added level 6
alex-setyawan Jan 31, 2024
b8a17cf
add JavaDocs to Task.java
alex-setyawan Feb 9, 2024
ecd3039
Add JavaDocs to TodoTask.java
alex-setyawan Feb 9, 2024
81fa62e
Clean up code, add more abstractions and JavaDocs
alex-setyawan Feb 11, 2024
bc932d1
Add factory methods for DeadlineTask.java and EventTask.java
alex-setyawan Feb 12, 2024
8e740c8
Add Level 7
alex-setyawan Feb 12, 2024
c70d672
Remove JavaDocs from master branch
alex-setyawan Feb 12, 2024
6081c95
Deconflicted TodoTask.java
alex-setyawan Feb 12, 2024
f88ac1b
Add various changes
alex-setyawan Feb 12, 2024
1aab432
Add Level-8
alex-setyawan Feb 13, 2024
8f524c4
Add JavaDocs to Task.java
alex-setyawan Feb 13, 2024
150effc
Merge branch 'branch-Level-8'
alex-setyawan Feb 13, 2024
e8807b5
Add Parser, Storage, TaskList and Ui classes
alex-setyawan Feb 13, 2024
e787551
Add A-MoreOOP
alex-setyawan Feb 14, 2024
5d7d33e
Merge branch 'branch-A-MoreOOP'
alex-setyawan Feb 14, 2024
c555db6
Add A-Packages
alex-setyawan Feb 14, 2024
d8c5937
Change runtest.bat
alex-setyawan Feb 14, 2024
ac056d1
Change filepaths to include packages
alex-setyawan Feb 14, 2024
2e2cad8
Merge branch 'add-gradle-support'
alex-setyawan Feb 14, 2024
5c97137
Add A-JUnit
alex-setyawan Feb 21, 2024
918454b
Merge branch 'branch-A-JUnit'
alex-setyawan Feb 21, 2024
345dd2c
Add A-Jar
alex-setyawan Feb 21, 2024
8509e36
Add some JavaDocs for A-JavaDoc
alex-setyawan Feb 21, 2024
f8cef40
Merge branch 'branch-A-JavaDoc'
alex-setyawan Feb 21, 2024
ee52925
Add A-CodingStandard
alex-setyawan Feb 21, 2024
bac18eb
Merge branch 'branch-A-CodingStandard'
alex-setyawan Feb 21, 2024
f06896e
Add Level-9
alex-setyawan Feb 21, 2024
900fc2f
Merge branch 'branch-Level-9'
alex-setyawan Feb 21, 2024
566c52f
Fix bug in TaskList.java
alex-setyawan Feb 21, 2024
7016d82
Add first attempt of Level-10
alex-setyawan Feb 25, 2024
d29dc09
Add second attempt of Level-10
alex-setyawan Feb 26, 2024
3b5168f
Merge branch 'branch-Level-10'
alex-setyawan Feb 26, 2024
8abb368
Add A-Assertions
alex-setyawan Feb 26, 2024
bde67b9
Add A-CodeQuality
alex-setyawan Feb 26, 2024
ac84b3b
Merge pull request #2 from alex-setyawan/branch-A-Assertions
alex-setyawan Feb 26, 2024
c4d739c
Merge branch 'master' of https://github.com/alex-setyawan/ip into bra…
alex-setyawan Feb 26, 2024
c82256c
Add some JavaDocs
alex-setyawan Feb 26, 2024
66cec4a
Merge branch 'branch-A-CodeQuality'
alex-setyawan Feb 26, 2024
12919e9
Add C-Help extension
alex-setyawan Feb 26, 2024
aba319d
Merge branch 'branch-BCD-Extension'
alex-setyawan Feb 26, 2024
05dd207
Add A-UserGuide
alex-setyawan Feb 26, 2024
edc80be
Add more JavaDocs
alex-setyawan Feb 26, 2024
4eb286f
Change mainClass in build.gradle
alex-setyawan Feb 26, 2024
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
130 changes: 130 additions & 0 deletions src/main/java/Awex.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import java.util.*;
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 try to avoid the use of wildcard imports here as it could lead to import conflicts.


public class Awex {
public static void message() {
Copy link

Choose a reason for hiding this comment

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

Good abstraction of the message to display the list of commands available. Perhaps a better and more specific variable name could be used here to describe this function? For example you could rename it to: listAllCommands()

System.out.println("Input type must be one of:");
System.out.println(" 1. list");
System.out.println(" 2. mark <task number>");
System.out.println(" 3. unmark <task number>");
System.out.println(" 4. todo <task>");
System.out.println(" 5. deadline <task> /by <deadline>");
System.out.println(" 6. event <task> /from <start> /to <end>");
System.out.println("Type 'bye' to exit.");
}

public static void main(String[] args) {
System.out.println("Hello! I'm AWEX!\nWhat can I do for you?");
LinkedList<Task> list = new LinkedList<>();
Copy link

Choose a reason for hiding this comment

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

Any reason why a LinkedList is used instead of an ArrayList? Indeed a LinkedList works similar to an ArrayList, although their use cases may vary depending on the scenario. Here is some research that I did: ArrayList vs LinkedList

Scanner sc = new Scanner(System.in);
String next = sc.nextLine();
String[] arr = next.split(" ");
while (!next.equals("bye")) {
Copy link

Choose a reason for hiding this comment

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

Good use of if-else statements to check and parse inputs! However, perhaps you could abstract out this method and also do consider using switch-case statements to improve performance.

if (next.equals("list")) {
if (arr.length > 1) {
message();
} else if (list.isEmpty()){
System.out.println("List is empty.");
} else {
System.out.println("Here are the tasks in your list:");
int len = list.size();
for (int i = 1; i <= len; i++) {
System.out.println(i + "." + list.get(i - 1).showAll());
}
}
} else if (arr[0].equals("mark")) {
String[] array = next.split(" ");
if (array.length != 2) {
System.out.println("Format should be 'mark <task number>'");
} else {
int i = Integer.parseInt(array[1]);
int len = list.size();
if (i > len) {
System.out.println("List has only " + len + " tasks.");
} else {
Task t = list.get(i - 1);
t.mark();
System.out.println(" " + t.showAll());
}
}
} else if (arr[0].equals("unmark")) {
String[] array = next.split(" ");
if (array.length != 2) {
System.out.println("Format should be 'unmark <task number>'");
} else {
int i = Integer.parseInt(array[1]);
int len = list.size();
if (i > len) {
System.out.println("List has only " + len + " tasks.");
} else {
Task t = list.get(i - 1);
t.unmark();
System.out.println(" " + t.showAll());
}
}
} else if (arr[0].equals("delete")) {
String[] array = next.split(" ");
if (array.length != 2) {
System.out.println("Format should be 'delete <task number>'");
} else {
int i = Integer.parseInt(array[1]);
int len = list.size();
if (i > len) {
System.out.println("List has only " + len + " tasks.");
} else {
System.out.println("Noted. I've removed this task:");
System.out.println(" " + list.remove(i - 1).showAll());
System.out.println("Now you have " + list.size() + " tasks in the list.");
}
}
} else {
Task t;
if (arr[0].equals("todo")) {
if (arr.length > 1) {
t = new TodoTask(arr[1]);
} else {
System.out.println("Format should be 'todo <task>'");
next = sc.nextLine();
arr = next.split(" ", 2);
continue;
}
} else if (arr[0].equals("deadline")) {
String[] array = next.split("/");
if (array.length != 2) {
System.out.println("Format should be 'deadline <task> /by <deadline>'");
next = sc.nextLine();
arr = next.split(" ", 2);
continue;
}
String[] hasWhat = arr[1].split("/", 2);
String[] hasTime = hasWhat[1].split(" ", 2);
t = new DeadlineTask(hasWhat[0], hasTime[1]);
} else if (arr[0].equals("event")){
String[] array = next.split("/");
if (array.length != 3) {
System.out.println("Format should be 'event <task> /from <start> /to <end>'");
next = sc.nextLine();
arr = next.split(" ", 2);
continue;
}
String[] hasWhat = arr[1].split("/", 2);
String[] hasTimes = hasWhat[1].split("/", 2);
String[] hasStart = hasTimes[0].split(" ", 2);
String[] hasEnd = hasTimes[1].split(" ", 2);
t = new EventTask(hasWhat[0], hasStart[1], hasEnd[1]);
} else {
message();
next = sc.nextLine();
arr = next.split(" ", 2);
continue;
}
list.add(t);
System.out.println("Got it. I've added this task:");
System.out.println(" " + t.showAll());
System.out.println("Now you have " + list.size() + " tasks in the list.");
}
next = sc.nextLine();
arr = next.split(" ", 2);
}
System.out.println("Bye. Hope to see you again soon!");
}
}
12 changes: 12 additions & 0 deletions src/main/java/DeadlineTask.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
public class DeadlineTask extends Task {
Copy link

Choose a reason for hiding this comment

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

Good use of inheritance!

private String type;
private String deadline;
public DeadlineTask(String what, String deadline) {
super(what);
this.type = "[D]";
this.deadline = deadline;
}
public String showAll() {
return this.type + super.showAll() + "(by: " + this.deadline + ")";
}
}
15 changes: 15 additions & 0 deletions src/main/java/EventTask.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
public class EventTask extends Task {
private String type;
private String start;
private String end;
public EventTask(String what, String start, String end) {
super(what);
this.type = "[E]";
this.start = start;
this.end = end;
}
public String showAll() {
return this.type + super.showAll()
+ "(from: " + this.start + " to: " + this.end + ")";
}
}
23 changes: 23 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
public class Task {
private String what;
private String done;

public Task(String what) {
this.what = what;
this.done = "[ ]";
}

public String showAll() {
return this.done + " " + this.what;
}

public void mark() {
this.done = "[X]";
System.out.println("Nice! I've marked this task as done:");
}

public void unmark() {
this.done = "[ ]";
System.out.println("OK, I've marked this task as not done yet:");
}
}
22 changes: 22 additions & 0 deletions src/main/java/TodoTask.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
public class TodoTask extends Task {
private String type;

/**
* Constuctor for Task object of type "todo"
*
* @param what description of the task
*/
public TodoTask(String what) {
super(what);
this.type = "[T]";
}

/**
* Returns string showing task type, completion status and description.
*
* @return string of task type, marked/unmarked status and description
*/
public String showAll() {
return this.type + super.showAll();
}
}
42 changes: 35 additions & 7 deletions text-ui-test/EXPECTED.TXT
Original file line number Diff line number Diff line change
@@ -1,7 +1,35 @@
Hello from
____ _
| _ \ _ _| | _____
| | | | | | | |/ / _ \
| |_| | |_| | < __/
|____/ \__,_|_|\_\___|

Got it. I've added this task:
[T][ ] borrow book
Now you have 1 tasks in the list.
Here are the tasks in your list:
1.[T][ ] borrow book
Got it. I've added this task:
[D][ ] return book (by: Sunday)
Now you have 2 tasks in the list.
Here are the tasks in your list:
1.[T][ ] borrow book
2.[D][ ] return book (by: Sunday)
Got it. I've added this task:
[E][ ] project meeting (from: Mon 2pm to: 4pm)
Now you have 3 tasks in the list.
Here are the tasks in your list:
1.[T][ ] borrow book
2.[D][ ] return book (by: Sunday)
3.[E][ ] project meeting (from: Mon 2pm to: 4pm)
Nice! I've marked this task as done:
[T][X] borrow book
Nice! I've marked this task as done:
[E][X] project meeting (from: Mon 2pm to: 4pm)
Here are the tasks in your list:
1.[T][X] borrow book
2.[D][ ] return book (by: Sunday)
3.[E][X] project meeting (from: Mon 2pm to: 4pm)
OK, I've marked this task as not done yet:
[T][ ] borrow book
OK, I've marked this task as not done yet:
[E][ ] project meeting (from: Mon 2pm to: 4pm)
Here are the tasks in your list:
1.[T][ ] borrow book
2.[D][ ] return book (by: Sunday)
3.[E][ ] project meeting (from: Mon 2pm to: 4pm)
Bye. Hope to see you again soon!
13 changes: 13 additions & 0 deletions text-ui-test/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
todo borrow book
list
deadline return book /by Sunday
list
event project meeting /from Mon 2pm /to 4pm
list
mark 1
mark 3
list
unmark 1
unmark 3
list
bye
2 changes: 1 addition & 1 deletion text-ui-test/runtest.bat
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ IF ERRORLEVEL 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 Awex < input.txt > ACTUAL.TXT

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