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

[Nathaniel Lukas] iP #477

Open
wants to merge 36 commits into
base: master
Choose a base branch
from

Conversation

dreammac3816547290
Copy link

@dreammac3816547290 dreammac3816547290 commented Aug 27, 2022

Duke

"The shorter way to do many things is to only do one thing at a time." - Mozart

Duke helps you keep track of ToDo, Event, and Deadline tasks. It's

  • TEXT-BASED
  • simple
  • powerful

All you need to do is

  1. download the duke.jar file from here.
  2. open the command prompt and navigate to the location of the downloaded file.
  3. type java -jar duke.jar and enter.
  4. use it however you want! 😃

Features:

  • Add ToDos, Deadlines, and Events.
  • List all tasks.
  • Delete tasks.
  • Mark tasks as done or not done.

If you are a Java programmer, you can use it to practice Java too. Here's the main method

public static void main(String[] args) {
    new Duke().start();
}

Copy link

@lpohsien lpohsien left a comment

Choose a reason for hiding this comment

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

Overall, I found the code easy to follow. The coding standard was consistent with only a few nits that might need fixing. Descriptive headers for public classes and methods could be included to allow for better documentation.

isDone = false;
}

public String data() {

Choose a reason for hiding this comment

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

Perhaps the name for the method could be change to one that starts with a verb like convertToData?

@@ -0,0 +1,32 @@
public class Task {

Choose a reason for hiding this comment

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

Perhaps this Task class and it's derived class could be put into a single package?

type = 'T';
}

public String getStatusIcon() {

Choose a reason for hiding this comment

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

Maybe you can add some method headers for the public methods?

System.out.println("Now you have " + tasks.size() + " tasks in the list.");
} else if (s.equals("deadline")) {
String rest = sc.nextLine();
String[] split = rest.split("/");

Choose a reason for hiding this comment

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

Considering that the split is an array of strings, perhaps it could named using the plural convention? Another way to name it could be tokens which might be more informative?

Copy link

@Tan-Jin-Waye Tan-Jin-Waye left a comment

Choose a reason for hiding this comment

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

Code employed is sufficient to pass muster for Level 7/8, but better design choices need to be applied for later levels. I assume you're busy with other commitments at the moment, in which case all the best.

Jiayous.

Comment on lines 16 to 90
if (s.equals("bye")) {
System.out.println("Bye. Hope to see you again soon!");
break;
} else if (s.equals("list")) {
System.out.println("Here are the tasks in your list:");
for (int a = 0; a < tasks.size(); a++) {
System.out.println((a + 1) + "." + tasks.get(a));
}
sc.nextLine();
} else if (s.equals("mark")) {
int index = sc.nextInt() - 1;
if (index >= tasks.size()) {
throw new DukeException("Index out of bound!");
}
tasks.get(index).markAsDone();
System.out.println("Nice! I've marked this task as done:");
System.out.println(tasks.get(index));
sc.nextLine();
} else if (s.equals("unmark")) {
int index = sc.nextInt() - 1;
if (index >= tasks.size()) {
throw new DukeException("Index out of bound!");
}
tasks.get(index).markNotDone();
System.out.println("OK, I've marked this task as not done yet:");
System.out.println(tasks.get(index));
sc.nextLine();
} else if (s.equals("todo")) {
String task = sc.nextLine();
if (task.trim().isEmpty()) {
throw new DukeException("☹ OOPS!!! The description of a todo cannot be empty.");
}
tasks.add(new Task(task));
System.out.println("Got it. I've added this task:");
System.out.println(tasks.get(tasks.size() - 1));
System.out.println("Now you have " + tasks.size() + " tasks in the list.");
} else if (s.equals("deadline")) {
String rest = sc.nextLine();
String[] split = rest.split("/");
String task = split[0];
String deadline = split[1];
deadline = deadline.substring(deadline.indexOf(' ') + 1);
tasks.add(new Deadline(task, deadline));
System.out.println("Got it. I've added this task:");
System.out.println(tasks.get(tasks.size() - 1));
System.out.println("Now you have " + tasks.size() + " tasks in the list.");
} else if (s.equals("event")) {
String rest = sc.nextLine();
String[] split = rest.split("/");
String task = split[0];
String time = split[1];
time = time.substring(time.indexOf(' ') + 1);
tasks.add(new Event(task, time));
System.out.println("Got it. I've added this task:");
System.out.println(tasks.get(tasks.size() - 1));
System.out.println("Now you have " + tasks.size() + " tasks in the list.");
} else if (s.equals("delete")) {
int index = sc.nextInt() - 1;
if (index >= tasks.size()) {
throw new DukeException("Index out of bound!");
}
tasks.remove(index);
System.out.println("Noted. I've removed this task:");
System.out.println(tasks.get(index));
System.out.println("Now you have " + tasks.size() + " tasks in the list.");
sc.nextLine();
} else {
String rest = sc.nextLine();
throw new DukeException("☹ OOPS!!! I'm sorry, but I don't know what that means :-(");
}
modify(tasks);
} catch (DukeException e) {
System.out.println(e.getMessage());
}
}

Choose a reason for hiding this comment

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

Do consider the use of a switch statement as opposed to a large if-else block.

switch (s) {
case "bye":
    // Code for exit
    break;
case "list":
    // Code for list print
   break;
...

Comment on lines 110 to 124
if (split[0].equals("T")) {
tasks.add(new Task(split[2]));
if (split[1].equals("1")) {
tasks.get(tasks.size() - 1).markAsDone();
}
} else if (split[0].equals("D")) {
tasks.add(new Deadline(split[2], split[3]));
if (split[1].equals("1")) {
tasks.get(tasks.size() - 1).markAsDone();
}
} else if (split[0].equals("E")) {
tasks.add(new Event(split[2], split[3]));
if (split[1].equals("1")) {
tasks.get(tasks.size() - 1).markAsDone();
}
Copy link

@Tan-Jin-Waye Tan-Jin-Waye Sep 1, 2022

Choose a reason for hiding this comment

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

Again, consider using a switch statement.
A switch fallthrough can be used to deal with the Deadline (line 115) and Event (line 120) cases elegantly.

switch (split[0]) {
case "T":
    // Code for Todo
    break;
case "D":
   // Fallthrough
case "E":
   // Code for Deadline and Event
   break;

Comment on lines 2 to 4
protected String description;
protected boolean isDone;
protected char type;

Choose a reason for hiding this comment

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

Nice use of protected, though realistically not necessary for description and isDone.

Comment on lines 21 to 26
public void markAsDone() {
isDone = true;
}

public void markNotDone() {
isDone = false;

Choose a reason for hiding this comment

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

May want to include some code to check if the user is attempting to markAsDone an already done task, and same for markNotDone, and respond to user accordingly.

dreammac3816547290 and others added 17 commits September 16, 2022 16:36
… at various points in the code

There are no checks to ensure the correctness of each aspect of the program (e.g. variable values at certain points in time).
It allows some bugs to be left undetected until an Exception happens and theprogram is terminated.
Adding assertions into the program acts as a sanity check and helps in ensuring the correctness of the program.
Use assert feature to document important assumptions that should hold…
…ssary

Important exceptions were not thrown, causing the program to terminate when bugs occur.

Exceptions need to be thrown and catch to ensure the code works as intended and to eliminate bugs.

Important exceptions are thrown and catch, and the error message is displayed in Duke GUI, especially for exceptions regarding array out of bound and incorrect syntax.
Examines the code and refactor to improve the code quality where nece…
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants