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

[azfarulmatin] IP #70

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Changes from 10 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
326786b
Add chatbot message
azfarulmatin Sep 5, 2023
942c0c4
Add level 1
azfarulmatin Sep 5, 2023
c971713
Add and list
azfarulmatin Sep 5, 2023
1eef87b
Mark as done
azfarulmatin Sep 5, 2023
ab74f0a
Add the ability to echo commands
azfarulmatin Sep 6, 2023
b8c0f92
Add list function for user to store tasks
azfarulmatin Sep 6, 2023
d668a45
Add the ability to mark tasks as done
azfarulmatin Sep 6, 2023
ad137e5
Tweak the code to comply with a coding standard
azfarulmatin Sep 6, 2023
7ffd63c
Add support for tracking todo, deadlines and events
azfarulmatin Sep 6, 2023
62bc7a5
Improve code quality
azfarulmatin Sep 6, 2023
2c6d3b6
Handle errors for todo
azfarulmatin Sep 15, 2023
aa236d0
Handle errors for todo event and deadline
azfarulmatin Sep 15, 2023
a3b8c95
Fix bugs for spacebar error
azfarulmatin Sep 15, 2023
47c7370
Divide classes into packages
azfarulmatin Sep 15, 2023
7d2298f
Fix bugs for task list quantity
azfarulmatin Sep 15, 2023
8b22a82
Fix bugs for marking and unmarking of tasks.
azfarulmatin Sep 15, 2023
7380c55
Add support for deleting tasks from list
azfarulmatin Sep 19, 2023
2da4d1d
Create a method to parse a string into a Task object and convert task…
azfarulmatin Sep 19, 2023
31bc5a8
Save task into the harddisk automatically whenever there are changes
azfarulmatin Sep 19, 2023
327f29d
FIx bugs
azfarulmatin Sep 21, 2023
87d459f
Merge branch 'branch-Level-6'
azfarulmatin Sep 21, 2023
8b28585
Merge branch 'branch-Level-7'
azfarulmatin Sep 21, 2023
4721aee
Add jar manifest
azfarulmatin Sep 21, 2023
9e5e42d
Refactor the code to separate classes
azfarulmatin Oct 6, 2023
80dd827
Fix bugs for delete task
azfarulmatin Oct 6, 2023
db3d7b7
Fix bugs when trying to save Deadline task
azfarulmatin Oct 6, 2023
2a15cd2
Add find function
azfarulmatin Oct 6, 2023
1b5de63
Add JavaDoc comments to the code
azfarulmatin Oct 6, 2023
a369c08
Update README.md
azfarulmatin Oct 6, 2023
b62c924
A-UserGuide
azfarulmatin Oct 6, 2023
d5a00ce
Fix bugs for txt file location
azfarulmatin Oct 6, 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
204 changes: 197 additions & 7 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,200 @@
import java.util.Scanner;
import java.util.Arrays;

class Task {
protected String description;
protected boolean isDone;

Choose a reason for hiding this comment

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

You did well in following the naming conventions (PascalCase for class and camelCase for variables)!!


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

Choose a reason for hiding this comment

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

you can consider spacing out (added new lines between) your functions for better readability

isDone = true;
}
public void markAsUndone() {
isDone = false;
}

Choose a reason for hiding this comment

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

you can consider combining this to become a setter method like "void setFound(boolean isFound);"

public boolean isDone() {
return isDone;
}
public String getDescription() {
return description;
}
public String getTaskType() {
return "Task";
}
@Override
public String toString() {
if (isDone) {
return "[X] "
+ description;

Choose a reason for hiding this comment

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

Any reason for separating it on different lines? It's a rather short line :)

} else {
return "[ ] "
+ description;
}
}
}

class Todo extends Task {
public Todo(String description) {
super(description);
}
@Override
public String getTaskType() {
return "Todo";
}
@Override
public String toString() {
return "[T]"
+ super.toString();
}
}

class Deadline extends Task {

Choose a reason for hiding this comment

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

having a new file for each class can keep your code more organised (abstraction)

protected String by;

public Deadline(String description, String by) {
super(description);
this.by = by;
}
@Override
public String getTaskType() {
return "Deadline";
}
@Override
public String toString() {
return "[D]"
+ super.toString()

Choose a reason for hiding this comment

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

The code uses string concatenation to build the final string for the object's representation. While this approach works, it can be a bit less readable, especially when dealing with multiple string elements. Consider using String.format() for improved readability and performance.

+ " (by: "
+ by
+ ")";
}
}

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 getTaskType() {
return "Event";
}
@Override
public String toString() {
return "[E]"
+ super.toString()
+ " (from: "
+ from
+ " to: "
+ to + ")";
}
}

public class Duke {
public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
String LINE = "__________________________________________\n";
System.out.println(LINE
+ "Hello I'm MatinBot\n"
+ "What can I do for you?\n"
+ LINE);

Scanner scanner = new Scanner(System.in);
Task[] tasks = new Task[100];

Choose a reason for hiding this comment

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

Good job on always having proper naming of functions, classes and variables! 👍

int count = 0;
String userInput;

while (true) {
// Get the user input first
userInput = scanner.nextLine();
System.out.println(LINE);

if (userInput.equals("bye")) {

Choose a reason for hiding this comment

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

could this be refactored into a switch statement for better readability?

break;
} else if (userInput.equals("list")) {
printTasks(tasks, count);
} else if (userInput.startsWith("mark ")) {
markTask(userInput, tasks);
} else if (userInput.startsWith("unmark ")) {
unmarkTask(userInput, tasks);
} else if (userInput.startsWith("todo ")) {
addTask(userInput, tasks, count, "Todo");
count++;
} else if (userInput.startsWith("deadline ")) {
addTask(userInput, tasks, count, "Deadline");
count++;
} else if (userInput.startsWith("event ")) {
addTask(userInput, tasks, count, "Event");
count++;
}
System.out.println(LINE);
}

System.out.println("Bye. Hope to see you again soon!\n" + LINE);
scanner.close();
}
}

// Create a task of a specific type to the tasks array
private static void addTask(String userInput, Task[] tasks, int count, String type) {
String description;
String bracketInfo;

Choose a reason for hiding this comment

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

Perhaps there might be a better more suggestive naming of the variable?


// Check for any inputs with '/'

Choose a reason for hiding this comment

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

I like how you added comments for easier readability! 👍

int checkSlash = userInput.indexOf("/");
if (checkSlash != -1) {
description = userInput.substring(type.length() + 1, checkSlash).trim();

Choose a reason for hiding this comment

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

Could this be refactored into a function? As we repeat it twice

bracketInfo = userInput.substring(checkSlash).trim();
} else {
description = userInput.substring(type.length() + 1).trim();
bracketInfo = "";
}

if (type.equals("Todo")) {
tasks[count] = new Todo(description);
} else if (type.equals("Deadline")) {
String by = bracketInfo.replace("/by", "").trim();
tasks[count] = new Deadline(description, by);
} else if (type.equals("Event")) {
String from = bracketInfo.split("/from")[1].split("/to")[0].trim();

Choose a reason for hiding this comment

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

The code is relatively concise, but it might benefit from some additional comments or variable names to make it more self-explanatory. For example, you could define variables with more descriptive names for the split values.

String to = bracketInfo.split("/to")[1].trim();
tasks[count] = new Event(description, from, to);
}

System.out.println("Got it. I've added this task:\n"
+ tasks[count]
+ "\nNow you have "
+ (count + 1)
+ " tasks in the list.");
}

// Print the task list
private static void printTasks(Task[] tasks, int count) {
System.out.println("Here are the tasks in your list:");
for (int i = 0; i < count; i++) {
System.out.println((i + 1)
+ ". "
+ tasks[i].toString());
}
}

// Mark a task as done

Choose a reason for hiding this comment

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

Great job in explicitly commenting on the purpose of functions you added!

private static void markTask(String userInput, Task[] tasks) {
int taskIndex = Integer.parseInt(userInput.substring(5)) - 1;
tasks[taskIndex].markAsDone();
System.out.println("Nice! I've marked this task as done:\n"
+ tasks[taskIndex]);
}

// Unmark a task
private static void unmarkTask(String userInput, Task[] tasks) {
int taskIndex = Integer.parseInt(userInput.substring(7)) - 1;
tasks[taskIndex].markAsUndone();
System.out.println("OK, I've marked this task as not done yet:\n"
+ tasks[taskIndex]);
}
}