-
Notifications
You must be signed in to change notification settings - Fork 116
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
[ThienDuc3112] iP #100
base: master
Are you sure you want to change the base?
[ThienDuc3112] iP #100
Conversation
Last commit I forgot to add list command
Also error handling
src/main/java/DBot.java
Outdated
@@ -0,0 +1,111 @@ | |||
import java.util.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid using wildcard imports
Import only the functions that you need
src/main/java/DBot.java
Outdated
isOn = true; | ||
datas = new ArrayList<>(); | ||
|
||
String greeting = "____________________________________________________________\n" + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use "final" and SCREAMING_SNAKE_CASE for the greeting variable as it is a constant
src/main/java/Task.java
Outdated
return isDone; | ||
} | ||
|
||
public void mark(){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a space before the "{" to keep layout consistent
src/main/java/DBot.java
Outdated
String line = in.nextLine().strip(); | ||
System.out.println("____________________________________________________________"); | ||
|
||
if (line.equals("bye")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Followed if else layout convention. Good job
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
src/main/java/DBot.java
Outdated
@@ -0,0 +1,111 @@ | |||
import java.util.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps you could import just the libraries you need?
src/main/java/DBot.java
Outdated
} else if (line.equals("list")) { | ||
list(); | ||
} else if (line.startsWith("mark ")) { | ||
mark(line); | ||
} else if (line.startsWith("unmark ")) { | ||
unmark(line); | ||
} else if (line.startsWith("todo ")) { | ||
todo(line); | ||
} else if (line.startsWith("event ")) { | ||
event(line); | ||
} else if (line.startsWith("deadline ")) { | ||
deadline(line); | ||
} else { | ||
add(line); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps you could refactor this into another function? This chunk is long and hard to read.
src/main/java/DBot.java
Outdated
|
||
private static void todo(String line) { | ||
String todo = line.substring(line.indexOf(" ") + 1).trim(); | ||
Todo task =new Todo(todo); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix the formatting after the = sign.
src/main/java/DBot.java
Outdated
|
||
public static void main(String[] args) { | ||
isOn = true; | ||
datas = new ArrayList<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps you could use a more descriptive name for your array list, as it is unclear what is being stored here.
return "[" + | ||
(isDone ? "X" : " ") + | ||
"] " + | ||
task; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps you could write this all in 1 line of code to make your code more readable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Solid effort
Code is following most of the code quality standards. The naming would need to be improved for better scalability so that fellow developers can understand the use of the method and variable easily. Consider adding JavaDocs in future commits
private static List<Task> taskList; | ||
|
||
public static void main(String[] args) { | ||
isOn = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using more descriptive names, that is easily identified to serve a definite purpose
src/main/java/DBot.java
Outdated
isOn = false; | ||
} else if (line.equals("list")) { | ||
list(); | ||
} else if (line.startsWith("mark ")) { | ||
mark(line); | ||
} else if (line.startsWith("unmark ")) { | ||
unmark(line); | ||
} else if (line.startsWith("todo ")) { | ||
todo(line); | ||
} else if (line.startsWith("event ")) { | ||
event(line); | ||
} else if (line.startsWith("deadline ")) { | ||
deadline(line); | ||
} else { | ||
System.out.println("Unknown command: " + line); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using switch case for this case, as the different cases of input is pre-determined
} | ||
} | ||
|
||
private static void list() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider naming it as listTasks
to avoid confusion with the inbuilt type
src/main/java/DBot.java
Outdated
int option = Integer.parseInt(line.substring(line.indexOf(" ") + 1)); | ||
System.out.println("Nice! I've marked this task as done:"); | ||
taskList.get(option - 1).mark(); | ||
System.out.println(taskList.get(option - 1).toString()); | ||
} catch (Exception e) { | ||
System.out.println("Invalid input, input must be a positive integer and must exist"); | ||
} | ||
} | ||
|
||
private static void unmark(String line) { | ||
try { | ||
int option = Integer.parseInt(line.substring(line.indexOf(" ") + 1)); | ||
System.out.println("OK, I've marked this task as not done yet:"); | ||
taskList.get(option - 1).unmark(); | ||
System.out.println(taskList.get(option - 1).toString()); | ||
} catch (Exception e) { | ||
System.out.println("Invalid input, input must be a positive integer and must exist"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using the same method or a central part for both functions as to reduce the number of duplicate lines of code
src/main/java/DBot.java
Outdated
System.out.println("Now you have " + taskList.size() + " tasks in the list."); | ||
} | ||
|
||
private static void event(String line) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider naming the methods better for easy maintainability and scalability
String from; | ||
String to; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider something like fromDate
, toDate
return "[" + | ||
(isDone ? "X" : " ") + | ||
"] " + | ||
task; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider same line implementation to increase code readability
src/main/java/Utilities.java
Outdated
|
||
public class Utilities { | ||
public static Hashtable<String, String> getCommandArgument(String line) { | ||
Hashtable<String, String> args = new Hashtable<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try to not use vague names for variables
No description provided.