@LowJiaHao99 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
Example from src/main/Duke.java lines 11-11:
//Task[] tasks = new Task[100];
Suggestion: Remove dead code from the codebase.
Aspect: Method Length
Example from src/main/Duke.java lines 8-163:
public static void main(String[] args) {
System.out.println(Commands.HI.toString());
ArrayList<Task> tasks = new ArrayList<Task>();
//Task[] tasks = new Task[100];
Scanner sc = new Scanner(System.in);
boolean isExit = false;
while (!isExit) {
String comm = sc.nextLine();
String[] processedCommand = comm.split(" ", 2);
Integer taskIndex = null;
switch (processedCommand[0]) {
case "hi":
System.out.println(Commands.HI.toString());
break;
case "bye":
System.out.println(Commands.BYE.toString());
isExit = true;
break;
case "list":
System.out.println(Commands.LIST.toString());
for (int i = 0; i < tasks.size(); i++) {
int indexToPrint = i + 1;
System.out.println(String.format(
" %d.%s", indexToPrint, tasks.get(i).identify()));
}
break;
case "mark":
//Exception catching
if (processedCommand.length <= 1) {
new DukeException();
break;
}
try {
taskIndex = Integer.parseInt(processedCommand[1]) - 1;
} catch (NumberFormatException e) {
new DukeException();
break;
}
//Mark task
tasks.get(taskIndex).setIsDone(true);
System.out.println(String.format(
"%s %s", Commands.MARK.toString(), tasks.get(taskIndex).identify()));
break;
case "unmark":
//Exception catching
if (processedCommand.length <= 1) {
new DukeException();
break;
}
try {
taskIndex = Integer.parseInt(processedCommand[1]) - 1;
} catch (NumberFormatException e) {
new DukeException();
break;
}
//Unmark task
tasks.get(taskIndex).setIsDone(false);
System.out.println(String.format(
"%s %s", Commands.UNMARK.toString(), tasks.get(taskIndex).identify()));
break;
case "deadline":
//Exception catching
if (processedCommand.length <= 1) {
new DukeException();
break;
} else if (!processedCommand[1].contains("/by")) {
new DukeException();
break;
}
//Processing input
String[] inputForDeadlineConstructor = processedCommand[1].split("/by", 2);
inputForDeadlineConstructor[0] = inputForDeadlineConstructor[0].trim();
LocalDate deadlineDate = null;
try {
deadlineDate = LocalDate.parse(inputForDeadlineConstructor[1].trim());
} catch (DateTimeParseException e) {
new DukeException();
break;
}
//Create deadline
Deadline deadline = new Deadline(inputForDeadlineConstructor[0], deadlineDate);
System.out.println(String.format(
"%s %s", Commands.ADD.toString(), deadline.identify()));
tasks.add(deadline);
System.out.println(String.format(" Now you have %d tasks in the list.", tasks.size()));
break;
case "todo":
//Exception catching
if (processedCommand.length <= 1) {
new DukeException();
break;
}
//Create Todo
ToDo todo = new ToDo(processedCommand[1]);
System.out.println(String.format(
"%s %s", Commands.ADD.toString(), todo.identify()));
tasks.add(todo);
System.out.println(String.format(" Now you have %d tasks in the list.", tasks.size()));
break;
case "event":
//Exception catching
if (processedCommand.length <= 1) {
new DukeException();
break;
} else if (!processedCommand[1].contains("/by")) {
new DukeException();
break;
}
//Input processing
String[] inputForEventConstructor = processedCommand[1].split("/by", 2);
inputForEventConstructor[0] = inputForEventConstructor[0].trim();
LocalDate eventDate = null;
try {
eventDate = LocalDate.parse(inputForEventConstructor[1].trim());
} catch (DateTimeParseException e) {
new DukeException();
break;
}
//Create event
Event event = new Event(inputForEventConstructor[0], eventDate);
System.out.println(String.format(
"%s %s", Commands.ADD.toString(), event.identify()));
tasks.add(event);
System.out.println(String.format(" Now you have %d tasks in the list.", tasks.size()));
break;
case "delete":
//Exception catching
if (processedCommand.length <= 1) {
new DukeException();
break;
}
try {
taskIndex = Integer.parseInt(processedCommand[1]) - 1;
} catch (NumberFormatException e) {
new DukeException();
break;
}
Task deletedTask = tasks.remove((int)taskIndex);
System.out.println(String.format(
"%s %s\n Now you have %d tasks in the list",
Commands.DELETE.toString(), deletedTask.identify(), tasks.size()));
break;
default:
new DukeException();
}
}
sc.close();
}
Example from src/test/java/ParserTest.java lines 22-71:
public void parse_InvalidInput_DukeExceptionThrown() {
try {
assertEquals(" ", Parser.parse(" ", -1).getCommand());
fail();
} catch (DukeException errorMessage) {
assertEquals(" Invalid input detected. Please check your input", errorMessage.getMessage());
}
try {
assertEquals("deadline", Parser.parse("deadline tmr ", 1).getCommand());
fail();
} catch (DukeException errorMessage) {
assertEquals(" Invalid input detected. Please check your input", errorMessage.getMessage());
}
try {
assertEquals("delete", Parser.parse("delete t", 1).getCommand());
fail();
} catch (DukeException errorMessage) {
assertEquals(" Invalid input detected. Please check your input", errorMessage.getMessage());
}
try {
assertEquals("deleted", Parser.parse("deleted 1", 1).getCommand());
fail();
} catch (DukeException errorMessage) {
assertEquals(" Invalid input detected. Please check your input", errorMessage.getMessage());
}
try {
assertEquals("listed", Parser.parse("listed", 1).getCommand());
fail();
} catch (DukeException errorMessage) {
assertEquals(" Invalid input detected. Please check your input", errorMessage.getMessage());
}
try {
assertEquals("event", Parser.parse("event homework /by Tmr", 1).getCommand());
fail();
} catch (DukeException errorMessage) {
assertEquals(" Invalid input detected. Please check your input", errorMessage.getMessage());
}
try {
assertEquals("event", Parser.parse("event homework /by 202-11-10", 1).getCommand());
fail();
} catch (DukeException errorMessage) {
assertEquals(" Invalid input detected. Please check your input", errorMessage.getMessage());
}
}
Example from src/test/java/StorageTest.java lines 52-95:
public void updateStorage_newTaskArrayList_containTasks() {
String filePath = "dataTest.txt";
File file = new File(filePath);
if (Files.exists(Paths.get(filePath))) {
try {
Files.delete(file.toPath());
} catch (IOException errorMessage) {
fail();
}
}
ArrayList<Task> tasks = new ArrayList<Task>();
tasks.add(new ToDo("sleep"));
tasks.add(new Event("run", LocalDate.parse("2021-10-10"), null));
tasks.add(new Event("do homework", LocalDate.parse("2021-12-05"), null));
Storage storage = new Storage(filePath);
try {
storage.updateStorageFile(tasks);
} catch (DukeException errorMessage) {
fail();
}
Scanner sc = null;
try {
sc = new Scanner(file);
} catch (FileNotFoundException errorMessage) {
fail();
}
for (int i = 0; i < 3; i++) {
String expectedOutput = String.format(" %s", tasks.get(i).toString());
assertEquals(sc.nextLine().concat("\n"), expectedOutput);
}
sc.close();
try {
Files.delete(Paths.get(filePath));
} catch (IOException errorMessage) {
fail();
}
}
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/dukeclasses/Duke.java lines 138-143:
/**
* Execute methods related to the find command.
*
* @param command command that contains information for find command to execute.
* @return String output that is printed in the GUI as Duke's response.
*/
Example from src/main/java/dukeclasses/Duke.java lines 152-157:
/**
* Execute methods related to the commands that change status of the task.
*
* @param command command that contains information for change of status command to execute.
* @return String output that is printed in the GUI as Duke's response.
*/
Example from src/main/java/dukeclasses/Duke.java lines 177-182:
/**
* Execute methods related to the commands that deletes task.
*
* @param command command that contains information for delete command to execute.
* @return String output that is printed in the GUI as Duke's response.
*/
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.
@LowJiaHao99 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
Example from
src/main/Duke.javalines11-11://Task[] tasks = new Task[100];Suggestion: Remove dead code from the codebase.
Aspect: Method Length
Example from
src/main/Duke.javalines8-163:Example from
src/test/java/ParserTest.javalines22-71:Example from
src/test/java/StorageTest.javalines52-95: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/dukeclasses/Duke.javalines138-143:Example from
src/main/java/dukeclasses/Duke.javalines152-157:Example from
src/main/java/dukeclasses/Duke.javalines177-182: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.