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

Increments for iP #370

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
aa829ae
no message
Jan 24, 2023
99c297e
no message
Jan 24, 2023
38c6d7f
no message
Jan 24, 2023
cda40e0
no message
Jan 24, 2023
1b106fd
no message
Jan 24, 2023
5c50031
no message
Jan 25, 2023
4cbf56c
no message
Jan 26, 2023
f28eaf2
Add "delete" feature to remove a task from the list
Jan 27, 2023
4e33f21
Add A-TextUiTesting to Duke environment
Jan 27, 2023
a31cf0c
Changes until MoreOOP
Feb 9, 2023
3d845a9
no message
Feb 15, 2023
d339498
Added "dates" feature
Feb 15, 2023
5c3b10d
Created package for "duke"
Feb 15, 2023
72d0760
Moved files to package folder
Feb 15, 2023
f9a3ce9
ADD gradle functionality
Feb 15, 2023
91d7ec7
ADD JUnit tests
Feb 15, 2023
34281ac
ADD find feature
Feb 15, 2023
cb2ebec
ADD Javadocs to public methods and classes
Feb 15, 2023
b2049d6
IMPROVE code quality
Feb 15, 2023
5baab08
ADD Varargs where applicable
Feb 15, 2023
cf661a8
no message
Feb 15, 2023
f16ad85
ADD GUI feature
Feb 16, 2023
7aac4f7
Add assertions to ensure that the user inputs are always valid.
Feb 16, 2023
d86e756
Improve code quality with better abstraction, closing platform featur…
Feb 16, 2023
95b378a
Add postpone feature to change the dates of deadlines to a later date.
Feb 16, 2023
2e1292d
Update README.md
Shuggan Feb 17, 2023
f7ca754
Add a representative screenshot
Shuggan Feb 17, 2023
af32516
Merge pull request #2 from Shuggan/branch-A-Assertions
Shuggan Feb 17, 2023
165951c
Merge pull request #3 from Shuggan/branch-A-CodeQuality
Shuggan Feb 17, 2023
ae5d801
Update README.md
Shuggan Feb 18, 2023
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
100 changes: 93 additions & 7 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,96 @@
import java.util.ArrayList;

Choose a reason for hiding this comment

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

Would prefer if the code was in a package, eg: package duke.

import java.util.Scanner;

public class Duke {
public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
ArrayList<Task> taskList = new ArrayList<Task>();
System.out.println("Hello I'm Duke\nWhat can I do for you?");
Scanner scan = new Scanner(System.in);

while (true) {
String textInput = scan.nextLine();

if (textInput.equalsIgnoreCase("bye")) {
System.out.println("Bye. Hope to see you again soon!");
scan.close();
return;
}

if (textInput.equalsIgnoreCase("list")) {
System.out.println("Here are the tasks in your list:");
for (int i = 0; i < taskList.size(); i++) {
System.out.println(i + 1 + ". " + taskList.get(i).toString());

Choose a reason for hiding this comment

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

This manual string formatting works, however, have you considered using Java's builtin String.format method?

}
continue;
}

if (textInput.length() >= 8 &&
textInput.substring(0, 6).equalsIgnoreCase("delete")) {
int i = Integer.parseInt(textInput.substring(7));
Task t = taskList.get(i - 1);
taskList.remove(i - 1);
String output = String.format("Got it. I've removed this task:\n%s\nNow you have %d tasks in the list", t.toString(), taskList.size());
System.out.println(output);
continue;

Choose a reason for hiding this comment

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

I find the use of multiple continue instructions in the code strange. The while loop already has a looping behaviour once it reaches the end of the loop, so using continue to return to the start of the loop should not be a default behaviour. What is your rationale for designing it this way?

Rather, I would suggest the following structure:

boolean isRunning = true;
while (isRunning) {
    if (textInput.equalsIgnoreCase("bye")) {
        isRunning = false;
    } else if (stmt) {
        code;
    } else {
        code;
    }
}

Alternatively, you may consider parsing the command first, then using a switch-case statement to handle various cases.

}

if (textInput.length() >= 6 &&
textInput.substring(0, 4).equalsIgnoreCase("mark")) {
int i = Integer.parseInt(textInput.substring(5));
Task currTask = taskList.get(i - 1);
currTask.markDone();
System.out.println("Nice! I've marked this task as done\n" + currTask.toString());
continue;
}

if (textInput.length() >= 8 &&
textInput.substring(0, 6).equalsIgnoreCase("unmark")) {
int i = Integer.parseInt(textInput.substring(7));
Task currTask = taskList.get(i - 1);
currTask.markUndone();
System.out.println("OK, I've marked this task as not done yet:\n" + currTask.toString());
continue;
}

if (textInput.length() >= 4 &&
textInput.substring(0, 4).equalsIgnoreCase("todo")) {
try {
String[] parts = textInput.split(" ", 2);
if (parts.length == 1 || parts[1] == "") {
throw new DukeException("☹ OOPS!!! The description of a todo cannot be empty.");
}
Task t = new Task.Todo(textInput.substring(5));
taskList.add(t);
String output = String.format("Got it. I've added this task:\n%s\nNow you have %d tasks in the list", t.toString(), taskList.size());

Choose a reason for hiding this comment

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

This output line seems very long, is it possible to split them into 2 lines?
A similar issue appears in line 32, 78, 88.

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

if (textInput.length() >= 10 &&
textInput.substring(0, 8).equalsIgnoreCase("deadline")) {
String[] parts = textInput.split("/");
Task t = new Task.Deadline(parts[0].substring(9), parts[1].substring(3));
taskList.add(t);
String output = String.format("Got it. I've added this task:\n%s\nNow you have %d tasks in the list", t.toString(), taskList.size());
System.out.println(output);
continue;
}

if (textInput.length() >= 7 &&
textInput.substring(0, 5).equalsIgnoreCase("event")) {
String[] parts = textInput.split("/");
Task t = new Task.Event(parts[0].substring(6), parts[1].substring(5), parts[2].substring(3));
taskList.add(t);
String output = String.format("Got it. I've added this task:\n%s\nNow you have %d tasks in the list", t.toString(), taskList.size());
System.out.println(output);
continue;
}

System.out.println("☹ OOPS!!! I'm sorry, but I don't know what that means :-(");
}
}
}
}
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.

For this class and your Task class, can you indent it with 4 spaces instead of 2?

public DukeException(String e) {
super(e);
}
}
72 changes: 72 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
public class Task {
protected String description;
protected boolean isDone;

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

public static class Todo extends Task {

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

@Override
public String toString() {
return "[T]" + super.toString();
}
}

public static class Deadline extends Task {

protected String by;

public Deadline(String description, String by) {
super(description);
this.by = by;
}

@Override
public String toString() {
return "[D]" + super.toString() + " (by: " + by + ")";
}
}

public static class Event extends Task {

protected String from;
protected String to;

public Event(String description, String from, String to) {
super(description);
this.from = from;
this.to = to;

}

@Override
public String toString() {
return "[E]" + super.toString() + " (from: " + from + "to: " + to + ")";
}
}

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

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

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

@Override
public String toString() {
String result = String.format("[%s] %s", this.getStatusIcon(), this.description);
return result;
}
}
10 changes: 3 additions & 7 deletions text-ui-test/EXPECTED.TXT
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
Hello from
____ _
| _ \ _ _| | _____
| | | | | | | |/ / _ \
| |_| | |_| | < __/
|____/ \__,_|_|\_\___|

Hello I'm Duke
What can I do for you?
☹ OOPS!!! I'm sorry, but I don't know what that means :-(
1 change: 1 addition & 0 deletions text-ui-test/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello
4 changes: 2 additions & 2 deletions text-ui-test/runtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ then
fi

# compile the code into the bin folder, terminates if error occurred
if ! javac -cp ../src/main/java -Xlint:none -d ../bin ../src/main/java/*.java
if ! javac -cp /Users/shane/Documents/NUS Y2S2/CS2103/ip/src/main/src/main/java -Xlint:none -d /Users/shane/Documents/NUS Y2S2/CS2103/ip/src/main/bin /Users/shane/Documents/NUS Y2S2/CS2103/ip/src/main/java/*.java
then
echo "********** BUILD FAILURE **********"
exit 1
fi

# 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 /Users/shane/Documents/NUS Y2S2/CS2103/ip/src/main/bin Duke < input.txt > ACTUAL.TXT

# convert to UNIX format
cp EXPECTED.TXT EXPECTED-UNIX.TXT
Expand Down