-
Notifications
You must be signed in to change notification settings - Fork 0
Description
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 code further.
IMPORTANT: Note that the script looked for just a few easy-to-detect problems only, and at-most one example is given i.e., there can be other areas/places to improve.
Aspect: Tab Usage
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.java lines 22-99:
public static void main(String[] params) throws IOException {
Scanner sc = new Scanner(System.in);
// Starting string to prime the program
String command = "Hello";
// Creating directory if it does not exist
File directory = new File("data");
if (!directory.exists()) {
boolean success = directory.mkdir();
if (!success) {
System.out.println("Directory creation was unsuccessful. Please " +
"manually create it.");
}
}
while (!command.equalsIgnoreCase("bye")) {
if (command.equals("Hello")) {
System.out.println("Hello! I'm Duke");
System.out.println("What can I do for you?");
} else if (command.startsWith("list")) {
enumerateTasks();
} else if (command.startsWith("done")) {
String[] taskToDelete = command.split("\\s+");
markAsDone(Integer.parseInt(taskToDelete[1]));
} else if (command.startsWith("todo")) {
try {
Todo currentTask = new Todo(command.substring(5));
addToTasks(currentTask);
logTask(currentTask);
} catch (StringIndexOutOfBoundsException indexError) {
System.out.println("☹ OOPS!!! The description of a todo cannot be empty.");
}
} else if (command.startsWith("event")) {
try {
String[] splitString = command.split("/at");
String eventDesc = splitString[0];
String eventDate = splitString[1];
Event currentTask = new Event(eventDesc.substring(6), eventDate);
addToTasks(currentTask);
logTask(currentTask);
} catch (ArrayIndexOutOfBoundsException | StringIndexOutOfBoundsException indexError) {
System.out.println("☹ OOPS!!! The description of an event cannot " +
"be empty.");
}
} else if (command.startsWith("deadline")) {
try {
String[] splitString = command.split("/by");
String eventDesc = splitString[0];
String eventDate = splitString[1];
String[] dateAndTime = eventDate.split("\\s+");
Deadline currentTask = new Deadline(eventDesc.substring(9), eventDate);
addToTasks(currentTask);
logTask(currentTask);
} catch (ArrayIndexOutOfBoundsException | StringIndexOutOfBoundsException indexError) {
System.out.println("☹ OOPS!!! The description of a deadline " +
"cannot be empty.");
}
} else if (command.startsWith("delete")) {
String[] splitString = command.split("\\s+");
removeTask(Integer.parseInt(splitString[1]));
} else {
// Command is not recognized
System.out.println("☹ OOPS!!! I'm sorry, but I don't know what that means :-(");
}
command = sc.nextLine();
}
BufferedWriter out = new BufferedWriter(new FileWriter("data/Duke.txt",
false));
out.write(logAllTasks());
out.close();
System.out.println("Bye. Hope to see you again soon!");
}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.
ℹ️ The bot account @cs2103-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.