Skip to content

Conversation

@matthanfoo
Copy link

@matthanfoo matthanfoo commented Feb 3, 2025

Chatty

Chatty helps you keep track of the million things on your to-do list, but it's also

  • text-based
  • easy to learn
  • SUPER FAST to use

All you need to do is,

  1. download it from here.
  2. double-click it.
  3. add your tasks.
  4. let it manage your tasks for you 😉

Here's what an example task list looks like:

Here are the tasks in your list:

  1. [T] [ ] borrow book
  2. [D] [X] return book /by 05-06-2022 (by: 2022-06-05T00:00)
  3. [E] [ ] project meeting /from 12-02-2025 14:00 /to 12-02-2025 17:00 (from: 2025-02-12T14:00 to: 2025-02-12T14:00)

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

public class Chatty {
   public static void main(String[] args) {
      new Chatty("ChattyData.csv").run();
   }
}

TRY IT OUT NOW!

damithc and others added 6 commits July 11, 2024 16:52
In build.gradle, the dependencies on distZip and/or distTar causes
the shadowJar task to generate a second JAR file for which the
mainClass.set("seedu.duke.Duke") does not take effect.
Hence, this additional JAR file cannot be run.
For this product, there is no need to generate a second JAR file
to begin with.

Let's remove this dependency from the build.gradle to prevent the
shadowJar task from generating the extra JAR file.
Copy link

@Nano-233 Nano-233 left a comment

Choose a reason for hiding this comment

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

I like how many potential user errors are considered and accounted for. Perhaps the code could be cleaner by refactoring?

System.out.println("What can I do for you?");
ArrayList<Task> userInputs = new ArrayList<Task>();
try {
String s = br.readLine();
Copy link

Choose a reason for hiding this comment

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

Should this have a more descriptive variable name? such as userInput

String s = br.readLine();
while (s != null) {
System.out.println("____________________________________________________________");
if (s.equals("bye") || s.equals("Bye")) {
Copy link

Choose a reason for hiding this comment

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

Would using s.equalsIgnoreCase("bye") here be more efficient and readable?

Comment on lines 30 to 31
Pattern p = Pattern.compile("([0-9]+$)");
Matcher m = p.matcher(s);
Copy link

Choose a reason for hiding this comment

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

Any reason this two line definition is used multiple times instead of using a helper method?
(for example again in line 52-53)

Comment on lines 18 to 143
if (s.equals("bye") || s.equals("Bye")) {
System.out.println("Bye. Hope to see you again soon!");
br.close();
break;
} else if (s.equals("list")) {
int i = 0;
System.out.println("Here are the tasks in your list:");
while (i != userInputs.size()) {
System.out.println(String.valueOf(i + 1) + ". " + userInputs.get(i));
i++;
}
} else if (s.contains("mark")) {
Pattern p = Pattern.compile("([0-9]+$)");
Matcher m = p.matcher(s);
if (m.find()) {
int i = Integer.parseInt(m.group(1)) - 1;
if (i < userInputs.size()) {
Task task = userInputs.get(i);
if (s.contains("unmark")) {
task.unmark();
System.out.println("OK, I've marked this task as not done yet:");
System.out.println(" " + task);
} else if (s.contains("mark")) {
task.mark();
System.out.println("Nice! I've marked this task as done:");
System.out.println(" " + task);
}
} else {
System.out.println("Invalid item");
}
} else {
System.out.println("Invalid item");
}
} else if (s.contains("delete")) {
Pattern p = Pattern.compile("([0-9]+$)");
Matcher m = p.matcher(s);
if (m.find()) {
int i = Integer.parseInt(m.group(1)) - 1;
if (i < userInputs.size()) {
Task task = userInputs.get(i);
System.out.println("Noted. I've removed this task:");
System.out.println(" " + task);
userInputs.remove(i);
System.out.println("Now you have " + userInputs.size() + " items in the list.");
} else {
System.out.println("Invalid item");
}
} else {
System.out.println("No such item");
}

} else {
if (s.contains("todo")) {
Pattern titlePattern = Pattern.compile("todo\\s*(.*)");
Matcher titlePatternMatcher = titlePattern.matcher(s);
String todoTitle = "";
if (titlePatternMatcher.find()) {
todoTitle = titlePatternMatcher.group(1);
} else {
System.out.println("Invalid title");
}

Todo t = new Todo(todoTitle);
userInputs.add(t);
System.out.println("Got it. I've added this task:\n " + t);
System.out.println("Now you have " + userInputs.size() + " items in the list.");
} else if (s.contains("event")) {
Pattern titlePattern = Pattern.compile("event\s*(.*?)\s+/");
Matcher titlePatternMatcher = titlePattern.matcher(s);
String eventTitle = "";
if (titlePatternMatcher.find()) {
eventTitle = titlePatternMatcher.group(1);
} else {
System.out.println("Invalid title");
}

Pattern fromPattern = Pattern.compile("/from\s*(.*?)\s+/");
Matcher fromPatternMatcher = fromPattern.matcher(s);
String fromString = "";
if (fromPatternMatcher.find()) {
fromString = fromPatternMatcher.group(1);
} else {
System.out.println("Invalid from timing");
}

Pattern toPattern = Pattern.compile("/to\\s*(.*)");
Matcher toPatternMatcher = toPattern.matcher(s);
String toString = "";
if (toPatternMatcher.find()) {
toString = toPatternMatcher.group(1);
} else {
System.out.println("Invalid to timing");
}

Event e = new Event(eventTitle, fromString, toString);
userInputs.add(e);
System.out.println("Got it. I've added this task:\n " + e);
System.out.println("Now you have " + userInputs.size() + " items in the list.");
} else if (s.contains("deadline")) {
Pattern titlePattern = Pattern.compile("deadline\s*(.*?)\s+/");
Matcher titlePatternMatcher = titlePattern.matcher(s);
String deadlineTitle = "";
if (titlePatternMatcher.find()) {
deadlineTitle = titlePatternMatcher.group(1);
} else {
System.out.println("Invalid title");
}

Pattern byPattern = Pattern.compile("/by\\s*(.*)");
Matcher byPatternMatcher = byPattern.matcher(s);
String byString = "";
if (byPatternMatcher.find()) {
byString = byPatternMatcher.group(1);
} else {
System.out.println("Invalid by timing");
}

Deadline d = new Deadline(deadlineTitle, byString);
userInputs.add(d);
System.out.println("Got it. I've added this task:\n " + d);
System.out.println("Now you have " + userInputs.size() + " items in the list.");

} else {
System.out.println("Invalid item");
break;
}
Copy link

Choose a reason for hiding this comment

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

Should switch-case be used instead of this many if-else statements to increase readability and maintainability?

System.out.println(" " + task);
}
} else {
System.out.println("Invalid item");
Copy link

Choose a reason for hiding this comment

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

For error messages, should there be logics or other ways to implement them so that they are not hardcoded?


} else {
System.out.println("Invalid item");
break;
Copy link

Choose a reason for hiding this comment

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

This may break the app as it breaks out of the while loop

Copy link

Choose a reason for hiding this comment

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

Should this code be refactored to improve readability and logic so that there are less hardcoding involved?

@matthanfoo matthanfoo changed the title Add Java files for initial stages # Chatty Feb 17, 2025
matthanfoo and others added 10 commits February 17, 2025 23:03
Parser execute method currently has much more than 50 LoC
and has too many levels/layers of nesting

Add new methods to Parser class in order to increase level of abstraction and also reduce length of execute method

Add recur functionality to create repeated tasks at daily/weekly/monthly/yearly intervals for a specified number of repetitions
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.

4 participants