@rycs2812 We did an automated analysis of your code to detect potential areas to improve the code quality. We are sharing the results below, to help you improve the iP code further.
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/Task.java
lines 10-10
:
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/Command.java
lines 35-127
:
public void run(String args, Duke duke) {
UI ui = duke.getUI();
TaskList taskList = duke.getTaskList();
Storage storage = duke.getStorage();
if (!isCorrectUsage(args, duke)) {
return;
}
switch(name) {
case "delete":
int index = Integer.parseInt(args) - 1;
Task t = taskList.deleteTask(index);
ui.printTaskDeleted(t, taskList.getCount());
try {
storage.rewriteFile(taskList.getTasks());
} catch (IOException e) {
ui.printError("Unable to write to file.");
}
break;
case "find":
if (args.charAt(0) == '"' && args.charAt(args.length() - 1) == '"') {
args = args.substring(1, args.length() - 1);
}
ArrayList<Task> matchingTasks = taskList.getMatchingTasks(args);
if (matchingTasks.isEmpty()) {
ui.print("No results found for keyword '" + args + "'");
} else {
ui.printTasks(matchingTasks, "Here are the matching tasks in your list:");
}
break;
case "list":
ui.printTasks(duke.getTaskList().getTasks(), "Here are the tasks in your list:");
break;
case "deadline":
String[] temp = args.split(" /by ", 2);
t = new Deadline(temp[0], LocalDate.parse(temp[1],
DateTimeFormatter.ofPattern(INPUT_DATE_FORMAT)));
taskList.addTask(t);
ui.printTaskAdded(t, taskList.getCount());
try {
storage.appendTaskToFile(t);
} catch (IOException e) {
ui.printError("Unable to write to file.");
}
break;
case "event":
temp = args.split(" /at ", 2);
t = new Event(temp[0], LocalDate.parse(temp[1],
DateTimeFormatter.ofPattern(INPUT_DATE_FORMAT)));
taskList.addTask(t);
ui.printTaskAdded(t, taskList.getCount());
try {
storage.appendTaskToFile(t);
} catch (IOException e) {
ui.printError("Unable to write to file.");
}
break;
case "todo":
t = new ToDo(args);
taskList.addTask(t);
ui.printTaskAdded(t, taskList.getCount());
try {
storage.appendTaskToFile(t);
} catch (IOException e) {
ui.printError("Unable to write to file.");
}
break;
case "mark":
// Fallthrough
case "unmark":
index = Integer.parseInt(args) - 1;
t = taskList.getTasks().get(index);
boolean b = name.equals("mark");
taskList.markTask(t, b);
ui.printTaskMarked(t, b);
try {
storage.rewriteFile(taskList.getTasks());
} catch (IOException e) {
ui.printError("Unable to write to file.");
}
break;
default:
break;
}
}
Example from src/main/java/duke/Command.java
lines 138-231
:
private boolean isCorrectUsage(String args, Duke duke) {
UI ui = duke.getUI();
TaskList taskList = duke.getTaskList();
String usage = getCorrectUsage();
switch(name) {
case "delete":
if (args.isEmpty()) {
ui.printError("Please specify a task number.\n\n" + usage);
return false;
}
return true;
case "find":
if (args.isBlank()) {
ui.printError("Please specify at least one keyword.\n\n" + usage);
return false;
} else if (args.charAt(0) != '"' || args.charAt(args.length() - 1) != '"') {
if (args.split(" ").length > 1) {
ui.printError("'find' only expects 1 argument.\n\n If there are multiple "
+ "keywords, please enclose them in quotation marks (\"\").");
return false;
}
} else {
if (args.length() == 2 || args.substring(1, args.length() - 1).isBlank()) {
ui.printError("Please specify at least one keyword.\n\n" + usage);
return false;
}
}
return true;
case "list":
if (!args.isEmpty()) {
ui.printError("'list' expects no arguments.");
return false;
}
return true;
case "deadline":
String[] temp = args.split(" /by ", 2);
if (temp.length < 2) {
ui.printError("Please specify a task and deadline.\n\n" + usage);
return false;
} else if (!isValidDate(temp[1])) {
ui.printError("Please specify the due date in the right format.\n\n" + usage);
return false;
}
return true;
case "event":
temp = args.split(" /at ", 2);
if (temp.length < 2) {
ui.printError("Please specify an event and date.\n\n" + usage);
return false;
} else if (!isValidDate(temp[1])) {
ui.printError("Please specify the event date in the right format.\n\n" + usage);
return false;
}
return true;
case "todo":
if (args.isEmpty()) {
ui.printError("Please specify a task.\n\n" + usage);
return false;
}
return true;
case "mark":
// Fallthrough
case "unmark":
if (args.isEmpty()) {
ui.printError("Please specify a task number\n\n" + usage);
return false;
} else {
try {
int index = Integer.parseInt(args) - 1;
if (index < 0 || index >= taskList.getCount()) {
ui.printError("Please specify a valid task number.\n"
+ "There are " + taskList.getCount()
+ " task(s) in the list.\n\n" + usage);
return false;
}
return true;
} catch (NumberFormatException e) {
ui.printError("Please specify a task number.\n\n"
+ "\"" + args + "\"" + " is not an item number\n" + usage);
return false;
}
}
default:
return false;
}
}
Example from src/main/java/duke/Storage.java
lines 27-79
:
public ArrayList<Task> load() throws FileNotFoundException {
File f = new File(filePath);
f.getParentFile().mkdirs();
try {
if (!f.exists()) {
f.createNewFile();
}
} catch (IOException e) {
System.out.println("Unable to read file.");
}
ArrayList<Task> tasks = new ArrayList<>();
Scanner s = new Scanner(f);
while (s.hasNext()) {
String nextTask = s.nextLine();
String[] temp = nextTask.split("\\[");
Character taskType = temp[1].charAt(0);
Boolean marked = temp[2].charAt(0) == 'X';
String dateTemp = temp[temp.length - 1];
dateTemp = dateTemp.substring(0, dateTemp.length() - 1);
LocalDate date = LocalDate.now();
if (!dateTemp.isEmpty()) {
date = LocalDate.parse(dateTemp);
}
String task = "";
for (int i = 3; i < temp.length - 1; ++i) {
if (i < temp.length - 2) {
task += temp[i];
task += "[";
} else {
task += temp[i].substring(0, temp[i].length() - 1);
}
}
switch(taskType) {
case 'T':
addTask(tasks, new ToDo(task), marked);
break;
case 'D':
addTask(tasks, new Deadline(task, date), marked);
break;
case 'E':
addTask(tasks, new Event(task, date), marked);
break;
default:
break;
}
}
return tasks;
}
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 ๐
โน๏ธ 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 [email protected]
if you want to follow up on this post.