-
Notifications
You must be signed in to change notification settings - Fork 0
Description
@VikramGoyal23 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
Example from src/main/java/task/Event.java lines 25-26:
}
else {Example from src/main/java/task/Event.java lines 36-37:
}
else {Example from src/main/java/task/Deadline.java lines 24-25:
}
else {Suggestion: As specified by the coding standard, use egyptian style braces.
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/main/Tyler.java lines 23-162:
public static void main(String[] args) throws IOException {
String logo = " _____ _ \n"
+ " |_ _| _| | ___ _ __ \n"
+ " | || | | | |/ _ \\ '__|\n"
+ " | || |_| | | __/ | \n"
+ " |_| \\__, |_|\\___|_| \n"
+ " |___/ \n";
System.out.println("Hello from\n" + logo);
String separator = "\t"
+ "____________________________________________________________\n";
String greeting = "\t" + " Hello! I'm Tyler!\n"
+ "\t" + " What can I do for you?\n";
String farewell = "\t" + " Bye-bye now!\n";
System.out.print(separator + greeting + separator);
Scanner sc = new Scanner(System.in);
ArrayList<Task> tasks = new ArrayList<>();
String home = System.getProperty("user.dir");
Path dirPath = Paths.get(home, "data");
boolean hasDataDir = Files.exists(dirPath);
if (!hasDataDir) {
Files.createDirectories(dirPath);
}
Path tylerPath = Paths.get(home,"data", "tyler.txt");
boolean hasTylerFile = Files.exists(tylerPath);
if (!hasTylerFile) {
Files.createFile(tylerPath);
}
List<String> stored = Files.readAllLines(tylerPath);
for (String item: stored) {
List<String> itemTokens = Arrays.asList(item.split("\\|"));
itemTokens.replaceAll(String::strip);
boolean isNewAdded = false;
if (itemTokens.get(0).equals("T") && itemTokens.size() == 3) {
tasks.add(new ToDo(itemTokens.get(2)));
isNewAdded = true;
} else if (itemTokens.get(0).equals("D") && itemTokens.size() == 4) {
tasks.add(new Deadline(itemTokens.get(2), LocalDateTime.parse(itemTokens.get(3))));
isNewAdded = true;
} else if (itemTokens.get(0).equals("E") && itemTokens.size() == 5) {
tasks.add(new Event(itemTokens.get(2),
LocalDateTime.parse(itemTokens.get(3)), LocalDateTime.parse(itemTokens.get(4))));
isNewAdded = true;
}
if (isNewAdded && itemTokens.get(1).equals("1")) {
tasks.get(tasks.size() - 1).markAsDone();
}
}
loop: while (true) {
try {
String input = sc.nextLine();
System.out.print(separator);
String[] tokens = input.split(" ", 2);
String command = tokens[0];
switch (command.toLowerCase()) {
case "list":
for (int j = 0; j < tasks.size(); j++) {
System.out.println("\t " + (j + 1) + ". " + tasks.get(j));
}
break;
case "bye":
break loop;
case "date":
LocalDate date = LocalDate.parse(tokens[1]);
int i = 1;
for (Task t : tasks) {
if (t.getCategory().equals("D")) {
if (((Deadline) t).getBy().toLocalDate().equals(date)) {
System.out.println("\t " + (i) + ". " + t);
i++;
}
} else if (t.getCategory().equals("E")) {
if (((Event) t).getFrom().toLocalDate().equals(date)
|| ((Event) t).getTo().toLocalDate().equals(date)) {
System.out.println("\t " + (i) + ". " + t);
i++;
}
}
}
break;
case "mark":
tasks.get(Integer.parseInt(tokens[1]) - 1).markAsDone();
break;
case "unmark":
tasks.get(Integer.parseInt(tokens[1]) - 1).markAsUndone();
break;
case "delete":
System.out.println("\t I've removed this task: \n"
+ "\t " + tasks.remove(Integer.parseInt(tokens[1]) - 1));
System.out.println("\t There are " + tasks.size() + " tasks left in the list.");
break;
case "todo":
ToDo toDo = new ToDo(tokens[1]);
Task.addToList(tasks, toDo);
break;
case "deadline":
if (!tokens[1].contains("/by") || tokens[1].split("/by ")[1].isBlank()) {
throw new IllegalArgumentException("\t !!Deadline must include a 'by' time!!");
}
Deadline deadline = new Deadline(
tokens[1].split(" /by")[0], tokens[1].split("/by ")[1]);
Task.addToList(tasks, deadline);
break;
case "event":
if (!tokens[1].contains("/from") || !tokens[1].contains("/to")
|| tokens[1].split("/from ")[1].split(" /to")[0].isBlank()
|| tokens[1].split("/to ")[1].isBlank()
) {
throw new IllegalArgumentException(
"\t !!Event must include a 'from' time and 'to' time!!");
}
Event event = new Event(tokens[1].split(" /from")[0],
tokens[1].split("/from ")[1].split(" /to")[0],
tokens[1].split("/to ")[1]);
Task.addToList(tasks, event);
break;
default:
throw new IllegalArgumentException("\t !!I'm sorry, I don't know what that means!!");
}
} catch (NumberFormatException e) {
System.out.println("\t !!Please enter a number as the argument!!");
} catch (IllegalArgumentException e) {
System.out.println(e.getMessage());
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("\t !!Please provide the correct number of arguments!!");
} catch (IndexOutOfBoundsException e) {
System.out.println("\t !!There aren't this many tasks in the list!!");
}
System.out.print(separator);
}
List<String> formattedTasks = getFormattedTasks(tasks);
Files.write(tylerPath, formattedTasks);
System.out.println(farewell + separator);
}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 Messages
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 cs2103@comp.nus.edu.sg if you want to follow up on this post.