@ovidharshini 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
No easy-to-detect issues 👍
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/Duke.java lines 48-124:
public void run() {
ui.showWelcome();
boolean isExit = false;
while (!isExit) {
try {
String input = ui.readInput();
String command = Parser.parse(input);
if (command.equals("")) {
ui.showCommandMessage(command, tasks);
continue;
}
input = Parser.handleInput(input);
switch (command) {
case "list":
ui.showCommandMessage(command, tasks);
break;
case "do":
int i = Integer.parseInt(input.replaceAll("[^0-9]",
"")) - 1;
tasks.get(i).markComplete();
ui.showCommandMessage(command, tasks);
break;
case "undo":
int j = Integer.parseInt(input.replaceAll("[^0-9]",
"")) - 1;
tasks.get(j).markIncomplete();
ui.showCommandMessage(command, tasks);
break;
case "delete":
int k = Integer.parseInt(input.replaceAll("[^0-9]",
"")) - 1;
tasks.remove(k);
ui.showCommandMessage(command, tasks);
break;
case "todo":
Todo t = new Todo(input);
tasks.add(t);
ui.showCommandMessage(command, tasks);
System.out.println(t);
break;
case "find":
ui.showCommandMessage(command, tasks);
System.out.println(tasks.find(input));
break;
case "deadline":
String datetime = input.replaceAll(".* by ", "");
input = input.replaceAll(" by .*", "");
Deadline d = new Deadline(input, datetime);
tasks.add(d);
ui.showCommandMessage(command, tasks);
System.out.println(d);
break;
case "event":
String time = input.replaceAll(".* at ", "");
input = input.replaceAll(" at .*", "");
Event e = new Event(input, time);
tasks.add(e);
ui.showCommandMessage(command, tasks);
System.out.println(e);
break;
default:
break;
}
if (!command.equals("list") && !command.equals("bye")) {
storage.save(tasks);
}
isExit = command.equals("bye");
} catch (Exception e) {
ui.showError(e.getMessage());
}
}
}
Example from src/main/java/duke/Parser.java lines 44-114:
public static String parse(String input) {
input = input.trim();
String command = input.replaceAll(" .*", "");
input = input.trim();
if (input.equals("bye") || input.equals("list")) {
return command;
}
// Handle do, undo, delete
String firstWord = input.replaceAll(" .*", "");
input = input.substring(firstWord.length()).trim();
switch (firstWord) {
case "do":
// Fallthrough
case "undo":
// Fallthrough
case "delete":
input = input.replaceAll(".* ", "");
if (input.matches("[0-9]+")) {
return command;
}
System.out.println("You need to specify the task you want to "
+ firstWord + " by its index :c");
return "";
case "todo":
if (input.equals("")) {
System.out.println("Oops, you need to mention what the "
+ "task is :c");
return "";
}
return command;
case "deadline":
if (!input.contains(" by ")) {
System.out.println("Oops, you need to format deadline tasks "
+ "as \"deadline X by Y\" :c");
return "";
}
String lastWord = input.substring(input.lastIndexOf(" ") + 1);
if (lastWord.equals("by")) {
return "";
}
return command;
case "event":
if (!input.contains(" at ")) {
System.out.println("Oops, you need to format event tasks "
+ "as \"event X at Y\" :c");
return "";
}
String finalWord = input.substring(input.lastIndexOf(" ") + 1);
if (finalWord.equals("at")) {
return "";
}
return command;
case "find":
if (input.equals("")) {
System.out.println("Oops, you need to mention what "
+ "the keyword is :c");
return "";
}
if (input.contains(" ")) {
System.out.println("Oops, you can only search for "
+ "one keyword at a time :c");
return "";
}
return command;
default:
return "";
}
}
Example from src/main/java/duke/Storage.java lines 55-102:
Storage(String filePath) throws IOException {
tasks = new ArrayList<>();
this.filePath = filePath;
File data = new File(filePath);
data.getParentFile().mkdirs();
//make preceding directories, if any are not found
ignoreResult(data.getParentFile().mkdirs());
// If file does not exist, create new file and return
if (data.createNewFile()) {
return;
}
Scanner fileReader = new Scanner(data);
while (fileReader.hasNextLine()) {
String line = fileReader.nextLine();
String[] tmp = line.split("\\|");
boolean isDone = tmp[1].trim().equals("D");
switch (tmp[0].trim()) {
case "T":
Todo t = new Todo(tmp[2].trim());
if (isDone) {
t.markComplete();
}
tasks.add(t);
break;
case "D":
Deadline d = new Deadline(tmp[2].trim(), tmp[3].trim());
if (isDone) {
d.markComplete();
}
tasks.add(d);
break;
case "E":
Event e = new Event(tmp[2].trim(), tmp[3].trim());
if (isDone) {
e.markComplete();
}
tasks.add(e);
break;
default:
throw new RuntimeException("Corrupted data in data file at "
+ filePath);
}
}
fileReader.close();
}
Suggestion: Consider applying SLAP (and other abstraction mechanisms) to shorten 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
Example from src/main/java/duke/Duke.java lines 126-131:
/**
* Main method that starts the program.
* It calls a new instance of Duke with a specified file path.
*
* @param args command-line arguments
*/
Example from src/main/java/duke/task/Task.java lines 56-62:
/**
* Default toString method that returns the description of Task with
* its completion status.
*
* @return formatted string of the description and completeness status
* of Task.
*/
Example from src/main/java/duke/task/TaskList.java lines 94-100:
/**
* Default toString method that returns a string of all tasks in
* TaskList and the number of tasks in TaskList.
*
* @return formatted string of all Tasks in TaskList and number of
* Tasks in TaskList delimited by newlines.
*/
Suggestion: Ensure method/class header comments follow the format specified in the coding standard, in particular, the phrasing of the overview statement.
Aspect: Recent Git Commit Message (Subject Only)
No easy-to-detect issues 👍
ℹ️ The bot account @nus-se-bot 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.
@ovidharshini 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
No easy-to-detect issues 👍
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/Duke.javalines48-124:Example from
src/main/java/duke/Parser.javalines44-114:Example from
src/main/java/duke/Storage.javalines55-102:Suggestion: Consider applying SLAP (and other abstraction mechanisms) to shorten 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
Example from
src/main/java/duke/Duke.javalines126-131:Example from
src/main/java/duke/task/Task.javalines56-62:Example from
src/main/java/duke/task/TaskList.javalines94-100:Suggestion: Ensure method/class header comments follow the format specified in the coding standard, in particular, the phrasing of the overview statement.
Aspect: Recent Git Commit Message (Subject Only)
No easy-to-detect issues 👍
ℹ️ The bot account @nus-se-bot 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.