@wengkit1 We did an automated analysis of your code to detect potential areas to improve the code quality. We are sharing the results below, so that you can avoid similar problems in your tP code (which will be graded more strictly for code quality).
IMPORTANT: Note that the script looked for just a few easy-to-detect problems only, and at-most three example are given i.e., there can be other areas/places to improve.
Aspect: Tab Usage
No easy-to-detect issues 👍
Aspect: Naming boolean variables/methods
Example from src/main/java/duke/taskmanager/Tasks.java lines 11-11:
Suggestion: Follow the given naming convention for boolean variables/methods (e.g., use a boolean-sounding prefix).You may ignore the above if you think the name already follows the convention (the script can report false positives in some cases)
Aspect: Brace Style
No easy-to-detect issues 👍
Aspect: Package Name Style
No easy-to-detect issues 👍
Aspect: Class Name Style
No easy-to-detect issues 👍
Aspect: Dead Code
No easy-to-detect issues 👍
Aspect: Method Length
Example from src/main/java/duke/bot/Parser.java lines 14-207:
public static String parse(String str, TaskList tasks) {
assert tasks != null;
StringBuilder res = new StringBuilder();
if (str.equals("bye")) {
Exit();
} else if (str.contains("delete")) {
if (tasks.isEmpty()) {
res.append("There is nothing on your list to delete");
return res.toString();
} else {
int index = Integer.parseInt((str.substring(7)));
Tasks t = tasks.get(index - 1);
tasks.remove(index - 1);
TaskList.rewrite(tasks);
res.append("\nNow you have ").append(tasks.size()).append(" tasks in the list");
System.out.println(t.deleted() +
"\nNow you have " +
tasks.size() +
" tasks in the list");
return res.toString();
}
} else if (str.contains("find")) {
System.out.println("Here are the tasks matching the description:");
res.append("Here are the tasks matching the description:");
if (str.split(" ", 2).length == 1) {
System.out.println("enter description you're looking for");
res.append("enter description you're looking for");
return res.toString();
}
String keyword = str.split(" ", 2)[1];
int n = 1;
for (Tasks t : tasks.getList()) {
if (t.getDesc().contains(keyword)) {
System.out.println(n + ". "
+ t.icon()
+ t.completed() + " "
+ t.getDesc());
res.append("\n" + res + n + ". "
+ t.icon()
+ t.completed() + " "
+ t.getDesc());
n++;
}
}
return res.toString();
} else if (str.contains("cleartags")){
int index = Integer.parseInt(str.split(" ",2 )[1]);
Tasks t = tasks.get(index - 1);
Tag.clearTags(t);
Tag.rewrite();
System.out.println("You've cleared tags for item" + index);
res.append("You've cleared tags for item" + index);
} else if (str.contains("tag")) {
if (str.contains("ged")) {
String k = str.split(" ", 2)[1];
System.out.println("Here are the items tagged as " + k);
res.append("Here are the items tagged as " + k + "\n");
System.out.println(Tag.returnTagged(k));
res.append(Tag.returnTagged(k));
return res.toString();
}
System.out.println("Nice I've tagged this item as: ");
res.append("Nice I've tagged this item as:");
Tasks taggedTask = tasks.get(Integer.parseInt(str.substring(3, 4))-1);
if(str.split(" ",2 ).length == 1) {
System.out.println("enter your tags(eg: fun, important...)");
res.append("enter your tags(eg: fun, important...)");
return res.toString();
}
String tags = str.split(" ", 2)[1];
int n = 1;
for (String t : tags.split(", ")) {
taggedTask.tag(t, taggedTask);
System.out.println(t + ", ");
res.append(t + ", ");
}
return res.toString();
} else {
if (str.equals("list")) {
System.out.println("Here are the tasks in your list:");
res.append("Here are the tasks in your list:");
if (tasks.isEmpty()) {
System.out.println("You have nothing scheduled, add something to the list.");
res.append("\nYou have nothing scheduled, add something to the list.");
return res.toString();
} else {
int n = 1;
for (Tasks t : tasks.getList()) {
System.out.println(n + ". "
+ t.icon()
+ t.completed() + " "
+ t.getDesc());
res.append("\n" + ". "
+ t.icon()
+ t.completed() + " "
+ t.getDesc());
n++;
}
return res.toString();
}
} else if (str.contains("mark")) {
if (str.contains("un")) {
int index = Integer.parseInt((str.substring(7)));
Tasks t = tasks.get(index - 1);
t.unmark();
TaskList.rewrite(tasks);
res.append("Oops! Stop procrastinating: \n"
+ t.completed() + " " + t.getDesc());
System.out.println("Oops! Stop procrastinating: \n"
+ t.completed() + " " + t.getDesc());
return res.toString();
} else {
int index = Integer.parseInt(str.substring(5));
Tasks t = tasks.get(index - 1);
t.mark();
TaskList.rewrite(tasks);
res.append("Nice! I've marked this task as done: \n"
+ t.completed() + " " + t.getDesc());
System.out.println("Nice! I've marked this task as done: \n"
+ t.completed() + " " + t.getDesc());
return res.toString();
}
} else {
String type = str.split(" ", 2)[0];
try {
switch (type) {
case "todo":
Tasks t = new ToDo(str);
tasks.add(t);
System.out.println(t.added() +
"\nNow you have " +
tasks.size() +
" tasks in the list");
res.append(t.added() +
"\nNow you have " +
tasks.size() +
" tasks in the list");
return res.toString();
case "deadline":
Tasks d = new Deadline(str);
tasks.add(d);
System.out.println(d.added() +
"\nNow you have " +
tasks.size() +
" tasks in the list");
res.append(d.added() +
"\nNow you have " +
tasks.size() +
" tasks in the list");
return res.toString();
case "event":
Tasks e = new Event(str);
tasks.add(e);
System.out.println(e.added() +
"\nNow you have " +
tasks.size() +
" tasks in the list");
res.append(e.added() +
"\nNow you have " +
tasks.size() +
" tasks in the list");
return res.toString();
default:
return res.toString();
}
} catch (UnrecogException e) {
System.out.println("☹ OOPS!!! I'm sorry, but I don't know what that means :-(\n");
res.append("☹ OOPS!!! I'm sorry, but I don't know what that means :-(\n");
return res.toString();
} catch (EmptyDescException e) {
System.out.println("☹ OOPS!!! The description of a " + type + " cannot be empty.\n");
res.append("☹ OOPS!!! The description of a " + type + " cannot be empty.\n");
return res.toString();
} catch (UnspecTimeException e) {
if (type.equals("event")) {
System.out.println(" Please specify a timeframe (from/ ... to/ ...)\n");
res.append(" Please specify a timeframe (from/ ... to/ ...)\n");
return res.toString();
} else {
System.out.println(" Please specify a deadline (by/...)\n");
res.append(" Please specify a deadline (by/...)\n");
return res.toString();
}
} catch (Exception ignored) {
return "OOps something went wrong!";
}
}
}
return res.toString();
}
Example from src/main/java/duke/taskmanager/Tag.java lines 53-99:
public static void rewrite() {
//rewrite file when un/mark or un/mark specific line if possible
PrintWriter writer;
File file = new File(FILE_PATH);
if (!file.exists()) {
file.mkdirs();
}
try {
writer = new PrintWriter("duke/bot/data/tasks.txt");
writer.close();
} catch (FileNotFoundException e) {
try {
writer = new PrintWriter(FILE_PATH);
writer.close();
} catch (FileNotFoundException IGNORED) {
}
}
Set<String> tags = uniTagsList.keySet();
BufferedWriter bw = null;
try {
bw = new BufferedWriter(new FileWriter("duke/bot/data/tasks.txt", true));
} catch (IOException e) {
try {
bw = new BufferedWriter(new FileWriter(FILE_PATH, true));
} catch (IOException IGNORED) {
}
}
for(String k : tags) {
for (String i : uniTagsList.get(k)) {
assert bw != null;
try {
bw.newLine();
bw.append(k + ":" + i);
} catch (IOException e) {
}
}
try {
assert bw != null;
bw.close();
} catch (NullPointerException | IOException ignored) {
}
}
}
Example from src/main/java/duke/taskmanager/TaskList.java lines 72-116:
public static void rewrite(TaskList lst) {
//rewrite file when un/mark or un/mark specific line if possible
PrintWriter writer;
File file = new File(FILE_PATH);
if (!file.exists()) {
file.mkdirs();
}
try {
writer = new PrintWriter("duke/bot/data/tasks.txt");
writer.close();
} catch (FileNotFoundException e) {
try {
writer = new PrintWriter(FILE_PATH);
writer.close();
} catch (FileNotFoundException IGNORED) {
}
}
List<Tasks> todos = lst.getList();
BufferedWriter bw = null;
try {
bw = new BufferedWriter(new FileWriter("duke/bot/data/tasks.txt", true));
} catch (IOException e) {
try {
bw = new BufferedWriter(new FileWriter(FILE_PATH, true));
} catch (IOException IGNORED) {
}
}
for(Tasks i : todos) {
assert bw != null;
try {
bw.newLine();
bw.append(i.icon()).append(" ∵ ").append(i.completed()).append(" ∵ ").append(i.desc.split(" ", 2)[1]);
} catch (IOException e) {
}
}
try {
assert bw != null;
bw.close();
} catch (NullPointerException | IOException ignored) {
}
}
Suggestion: Consider applying SLAP (and other abstraction mechanisms) to shorten methods e.g., extract some code blocks into separate methods. You may ignore this suggestion if you think a longer method is justified in a particular case.
Aspect: Class size
No easy-to-detect issues 👍
Aspect: Header Comments
No easy-to-detect issues 👍
Aspect: Recent Git Commit Message (Subject Only)
No easy-to-detect issues 👍
Aspect: Binary files in repo
No easy-to-detect issues 👍
❗ You are not required to (but you are welcome to) fix the above problems in your iP, unless you have been separately asked to resubmit the iP due to code quality issues.
ℹ️ The bot account used to post this issue is un-manned. Do not reply to this post (as those replies will not be read). Instead, contact cs2103@comp.nus.edu.sg if you want to follow up on this post.
@wengkit1 We did an automated analysis of your code to detect potential areas to improve the code quality. We are sharing the results below, so that you can avoid similar problems in your tP code (which will be graded more strictly for code quality).
IMPORTANT: Note that the script looked for just a few easy-to-detect problems only, and at-most three example are given i.e., there can be other areas/places to improve.
Aspect: Tab Usage
No easy-to-detect issues 👍
Aspect: Naming boolean variables/methods
Example from
src/main/java/duke/taskmanager/Tasks.javalines11-11:Suggestion: Follow the given naming convention for boolean variables/methods (e.g., use a boolean-sounding prefix).You may ignore the above if you think the name already follows the convention (the script can report false positives in some cases)
Aspect: Brace Style
No easy-to-detect issues 👍
Aspect: Package Name Style
No easy-to-detect issues 👍
Aspect: Class Name Style
No easy-to-detect issues 👍
Aspect: Dead Code
No easy-to-detect issues 👍
Aspect: Method Length
Example from
src/main/java/duke/bot/Parser.javalines14-207:Example from
src/main/java/duke/taskmanager/Tag.javalines53-99:Example from
src/main/java/duke/taskmanager/TaskList.javalines72-116:Suggestion: Consider applying SLAP (and other abstraction mechanisms) to shorten methods e.g., extract some code blocks into separate methods. You may ignore this suggestion if you think a longer method is justified in a particular case.
Aspect: Class size
No easy-to-detect issues 👍
Aspect: Header Comments
No easy-to-detect issues 👍
Aspect: Recent Git Commit Message (Subject Only)
No easy-to-detect issues 👍
Aspect: Binary files in repo
No easy-to-detect issues 👍
❗ You are not required to (but you are welcome to) fix the above problems in your iP, unless you have been separately asked to resubmit the iP due to code quality issues.
ℹ️ The bot account used to post this issue is un-manned. Do not reply to this post (as those replies will not be read). Instead, contact
cs2103@comp.nus.edu.sgif you want to follow up on this post.