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

[shunjieee] iP #455

Open
wants to merge 65 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
65 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
c4f0b7c
Duke.java: Add Level-0 requirements
Jan 25, 2024
63aaba6
Duke.java: Add Level-1 requirements
Jan 25, 2024
60e044f
Duke.java: Add Level-2 requirements
Jan 25, 2024
3dcf67f
Add helperpackage and Task.java
Jan 25, 2024
5c6a182
Duke.java: Add Level-3 requirements
Jan 25, 2024
7e74b17
Add Deadline.java
Jan 30, 2024
3477c2a
Add Event.java
Jan 30, 2024
e2862b0
ToDo.java
Jan 30, 2024
e38ae26
Update test cases and expected results
Jan 30, 2024
c527c2b
Deadline.java: Add DukeException for invalid inputs
Feb 1, 2024
8f063a8
Event.java: Add DukeException for invalid inputs
Feb 1, 2024
6ccab68
Add DukeException.java
Feb 1, 2024
0ebbf06
Duke.java: Add try-catch for exceptions
Feb 1, 2024
b884da4
Duke.java: Add Level-6 requirements
Feb 1, 2024
02c1ec3
Add ToDo.java
Jan 30, 2024
6389e2f
Merge commit '02c1ec31378fffb8932bc84b33ea9c024e97ce70'
Feb 5, 2024
52aa83d
Add toData() function
Feb 7, 2024
d09f72d
Add branch-Level-7 requirements
Feb 7, 2024
002c741
Merge branch 'branch-Level-7'
Feb 7, 2024
8794e7b
Change deadline from String to LocalDateTime
Feb 7, 2024
5bdb39f
Change startAndEndTime from String to LocalDateTime
Feb 7, 2024
36fc9c1
Add branch-Level-8 requirements
Feb 7, 2024
9edacad
Merge branch 'branch-Level-8'
Feb 7, 2024
78c4609
Update format of input
Feb 16, 2024
66be4d7
Merge branch 'master' into branch-A-MoreOOP
Feb 16, 2024
7c544b8
Add Ui.java and Storage.java
Feb 16, 2024
d2b525d
Add TaskList.java
Feb 17, 2024
c14ea0b
Add Parser.java
Feb 18, 2024
0a2e5cc
Add command package
Feb 18, 2024
ed6a9e1
Merge branch 'branch-A-MoreOOP'
Feb 18, 2024
273756d
Merge branch 'add-gradle-support' into branch-Level-9
Feb 22, 2024
84f6c79
Revert "Merge branch 'add-gradle-support' into branch-Level-9"
Feb 22, 2024
1edebbc
Add Level-9 requirements
Feb 25, 2024
eb0a523
Update files to match coding standards
Feb 25, 2024
512850b
Update files to include JavaDocs and comments
Feb 26, 2024
7dc4874
Merge branch 'branch-A-JavaDoc'
Feb 26, 2024
c3021a5
Merge branch 'branch-A-CodingStandard'
Feb 26, 2024
a1312ca
Merge branch 'branch-Level-9'
Feb 26, 2024
f6366fc
Storage.java: Resolve merge conflict
Feb 26, 2024
6f053af
Update gradle filepath
Feb 26, 2024
174c867
Merge branch 'add-gradle-support'
Feb 26, 2024
4fb3e11
Add JUnit test for Deadline.java and Event.java
Feb 26, 2024
b975ff1
Update coding standard according to checkstyle
Feb 26, 2024
f5313e0
Add GUI and Level-10 requirement
Feb 29, 2024
e7e3cee
Add GUI and Level 10 requirement
Feb 29, 2024
4249056
Revert "Add GUI and Level 10 requirement"
Feb 29, 2024
695fc44
Merge branch 'branch-Level-10'
Feb 29, 2024
19b1366
Add assertions for add, delete, mark and unmark
Feb 29, 2024
0593345
Merge pull request #2 from shunjieee/branch-A-Assertions
shunjieee Feb 29, 2024
b3709df
Improve code quality
Feb 29, 2024
02139f1
Merge pull request #3 from shunjieee/branch-A-CodeQuality
shunjieee Feb 29, 2024
3f8ae17
Merge branch 'master' of github.com:shunjieee/ip
Feb 29, 2024
9ef7366
Add sort command
Feb 29, 2024
8855b03
Update GUI and add Ui.png
Feb 29, 2024
b27fbdc
README.md: Add User Guide
Feb 29, 2024
94485a0
Update README.md
shunjieee Feb 29, 2024
17dbcf3
Update README.md
shunjieee Feb 29, 2024
688934e
Update README.md
shunjieee Feb 29, 2024
7eb276c
Update README.md
shunjieee Feb 29, 2024
64e3c42
Update README.md
shunjieee Feb 29, 2024
5091616
Merge branch 'master' of github.com:shunjieee/ip
Feb 29, 2024
e982e06
Update README.md
shunjieee Feb 29, 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
156 changes: 156 additions & 0 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
import helperpackage.Deadline;
import helperpackage.DukeException;
import helperpackage.Event;
import helperpackage.Task;
import helperpackage.ToDo;

import java.util.LinkedList;
import java.util.NoSuchElementException;
import java.util.Scanner;
import java.util.StringTokenizer;
Copy link

Choose a reason for hiding this comment

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

Suggested change
import helperpackage.Deadline;
import helperpackage.DukeException;
import helperpackage.Event;
import helperpackage.Task;
import helperpackage.ToDo;
import java.util.LinkedList;
import java.util.NoSuchElementException;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.LinkedList;
import java.util.NoSuchElementException;
import java.util.Scanner;
import java.util.StringTokenizer;
import helperpackage.Deadline;
import helperpackage.DukeException;
import helperpackage.Event;
import helperpackage.Task;
import helperpackage.ToDo;


public class Duke {
public static void main(String[] args) {
String logo = " ____ _ \n"
Expand All @@ -6,5 +17,150 @@ public static void main(String[] args) {
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
System.out.println("________________________________________");

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

Scanner scanner = new Scanner(System.in);
String userInput = scanner.nextLine();

/** Used to store Tasks */
LinkedList<Task> taskList = new LinkedList<>();

// loop only exits if input is "bye"
while (!userInput.toLowerCase().equals("bye")) {
System.out.println("\n________________________________________");

// Level-2: if the input is "list"
if (userInput.toLowerCase().equals("list")) {
System.out.println("Here are the tasks in your list:");

for (int i = 1; i <= taskList.size(); i++) {
Task t = taskList.get(i - 1);
System.out.println(i + ". " + t.toString());
}

} else {
StringTokenizer st = new StringTokenizer(userInput);
String cmd = st.nextToken().toLowerCase();

// Level-3: mark & unmark
if (cmd.equals("mark") || (cmd.equals("unmark"))) {
try {
changeStatus(taskList, cmd, st);
} catch (IndexOutOfBoundsException e) {
System.out.println("Task not found. :(");

} catch (NumberFormatException e) {
System.out.println("Input is not an integer. :(");

} catch (NoSuchElementException e) {
System.out.println("Missing task number. :(");
}

// Level-4: ToDo, Deadline, Event
} else if (cmd.equals("todo") || cmd.equals("event") || cmd.equals("deadline")) {
try {
addTask(taskList, cmd, userInput);

} catch (DukeException e) {
System.out.println(e.getMessage());

} catch (StringIndexOutOfBoundsException e) {
System.out.println("Invalid input. :(");
}

// Level-6: Delete
} else if (cmd.equals("delete")) {
try {
delete(taskList, cmd, st);
} catch (IndexOutOfBoundsException e) {
System.out.println("Task not found. :(");

} catch (NumberFormatException e) {
System.out.println("Input is not an integer. :(");

} catch (NoSuchElementException e) {
System.out.println("Missing task number. :(");
}

// Level-5: Throw exception for other inputs
} else {
try {
throw new DukeException("OOPS!! Pls try again. :)");
} catch (DukeException e) {
System.out.println(e.getMessage());
}
}
}
System.out.println("________________________________________\n");
userInput = scanner.nextLine();
}

System.out.println("\n________________________________________");
System.out.println("Bye. Hope to see you again soon!");
System.out.println("________________________________________\n");

scanner.close();
}

// Level-3: mark & unmark
public static void changeStatus(LinkedList<Task> taskList, String cmd, StringTokenizer st) throws IndexOutOfBoundsException,
Copy link

Choose a reason for hiding this comment

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

I like how you use line wrapping at appropriate place of this line

NumberFormatException, NoSuchElementException {

int index = Integer.parseInt(st.nextToken());
Task t = taskList.get(index - 1);

if (cmd.equals("mark")) {
t.markAsDone();
System.out.println("Nice! I've marked this task as done:");

} else if (cmd.equals("unmark")) {
t.unmark();
System.out.println("OK, I've marked this task as not done yet:");
}

System.out.println(" " + t.toString());
}

// Level-4: ToDo, Deadline, Event
public static void addTask(LinkedList<Task> taskList, String cmd, String userInput) throws DukeException {
int firstSpaceIndex = userInput.indexOf(" ");
String description = userInput.substring(firstSpaceIndex + 1);
Copy link

Choose a reason for hiding this comment

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

Here the description means the whole part following the command type, while in the Task class another description means solely the description part of a task, which would be a little misleading or ambiguous. Would it be better to change the variable name here?

Task t = new Task(" ");

if (cmd.equals("todo")) {
description = description.strip();
if (description.equals("") || firstSpaceIndex == -1) {
throw new DukeException("Invalid todo input. :(");
} else {
t = new ToDo(description);
}

} else if (cmd.equals("deadline")) {
t = new Deadline(description);

} else if (cmd.equals("event")) {
t = new Event(description);
}

taskList.add(t);
System.out.println("Got it. I've added this task:");
System.out.println(" " + t.toString());
System.out.println("Now you have " + taskList.size() + " tasks in the list.");
}

// Level-6: Delete
public static void delete (LinkedList<Task> taskList, String cmd, StringTokenizer st) throws IndexOutOfBoundsException,
NumberFormatException, NoSuchElementException {

int index = Integer.parseInt(st.nextToken());
Copy link

Choose a reason for hiding this comment

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

The name index doesn't explain its meaning accurately. Could you try to specify what the index stands for, like the firstSpaceIndex in your code above?

Task t = taskList.remove(index - 1);

System.out.println("Noted, I've removed this task:");
System.out.println(" " + t.toString());
System.out.println("Now you have " + taskList.size() + " tasks in the list.");
}
Copy link

Choose a reason for hiding this comment

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

Suggested change
int index = Integer.parseInt(st.nextToken());
Task t = taskList.remove(index - 1);
System.out.println("Noted, I've removed this task:");
System.out.println(" " + t.toString());
System.out.println("Now you have " + taskList.size() + " tasks in the list.");
}
int index = Integer.parseInt(st.nextToken());
Task t = taskList.remove(index - 1);
System.out.println("Noted, I've removed this task:");
System.out.println(" " + t.toString());
System.out.println("Now you have " + taskList.size() + " tasks in the list.");
}

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

public class Deadline extends Task {
protected String deadline;

public Deadline(String description) throws DukeException {
super(description.substring(0, description.indexOf("/")));
String deadline = description.substring(description.indexOf("/")).replace("/by", "by:");

if (!deadline.contains("by:")) {
throw new DukeException("Invalid deadline input. :(");
}

this.deadline = deadline;
}

@Override
public String toString() {
return "[D]" + super.toString() + "(" + deadline + ")";
}
}
9 changes: 9 additions & 0 deletions src/main/java/helperpackage/DukeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package helperpackage;

public class DukeException extends Exception {

// constructor
public DukeException(String message) {
super(message);
}
}
22 changes: 22 additions & 0 deletions src/main/java/helperpackage/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package helperpackage;

public class Event extends Task {
protected String startAndEndTime;

public Event(String description) throws DukeException {
super(description.substring(0, description.indexOf("/")));
String time = description.substring(description.indexOf("/")).replace("/from",
"from:").replace("/to", "to:");

if (!(time.contains("from:") || time.contains("to:"))) {
throw new DukeException("Invalid event input. :(");
}

this.startAndEndTime = time;
}

@Override
public String toString() {
return "[E]" + super.toString() + "(" + startAndEndTime + ")";
}
}
50 changes: 50 additions & 0 deletions src/main/java/helperpackage/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package helperpackage;

/**
* Creates an instance of Task.
*/
public class Task {
/** Task description, also the user input */
protected String description;
/** Status of the task, done or not done */
protected boolean isDone;
Copy link

Choose a reason for hiding this comment

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

I like how you name the Boolean variable 😃


/**
* Returns an instance of Task, a constructor.
*
* @param description User-defined task name.
*/
public Task(String description) {
this.description = description;
this.isDone = false;
}

/**
* Returns the status of the task.
*
* @return A string to indicate the status.
*/
public String getStatusIcon() {
return (isDone ? "[X] " : "[ ] "); // mark done task with X
}

/**
* Sets the status of task as done.
*/
public void markAsDone() {
this.isDone = true;
}

/**
* Sets the status of task as not done.
*/
public void unmark() {
this.isDone = false;
}

@Override
public String toString() {
return getStatusIcon() + description;
}
}

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

public class ToDo extends Task {

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

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

________________________________________
Hello! I'm NextGenerationJarvis.
What can I do for you?
________________________________________


________________________________________
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.
________________________________________


________________________________________
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:
[D][X] return book (by: Sunday)
________________________________________


________________________________________
OK, I've marked this task as not done yet:
[T][ ] borrow book
________________________________________


________________________________________
Bye. Hope to see you again soon!
________________________________________

9 changes: 9 additions & 0 deletions text-ui-test/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
todo borrow book
list
deadline return book /by Sunday
event project meeting /from Mon 2pm /to 4pm
list
mark 1
mark 2
unmark 1
bye
Empty file modified text-ui-test/runtest.sh
100644 → 100755
Empty file.