@imrajsinghsandhu 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/java/Duke.java
lines 90-90
:
// Task[] list = new Task[100];
Example from src/main/java/Duke.java
lines 159-159
:
// Task currTask = list[number];
Example from src/main/java/Duke.java
lines 170-170
:
// Task currTask = list[number];
Suggestion: Remove dead code from the codebase.
Aspect: Method Length
Example from src/main/java/Duke.java
lines 87-254
:
public static void main(String[] args) throws IOException, DukeException {
// an array of tasks
// Task[] list = new Task[100];
int counter = 0;
System.out.println(GREETING);
// new Data Structure to hold the tasks
ArrayList<Task> tasks = new ArrayList<Task>();
// takes in the incoming prompt
Scanner sc = new Scanner(System.in);
// checks for the existence of data directory
// and the duke.txt file
File completeDirectory = new File("data/duke.txt");
File dataFolder = new File("data");
String dataPath = "data/duke.txt";
// Check if the data directory exists.
// Then create duke.txt if it doesnt.
// if the folder and file exits, then we read the messages in there,
// and update our tasks ArrayList.
if (!completeDirectory.exists()) {
if (!dataFolder.exists()) {
// neither the full path nor the Folder exits
// proceed to create the dataFolder first
dataFolder.mkdir();
}
// here we will create the duke.txt file
completeDirectory.createNewFile();
} else {
System.out.println("duke.txt already exists");
// add the elements in the file to the tasks here
// replacing the ArrayList Tasks
tasks = ParseDukeTxt.readFile(completeDirectory);
}
// Outputs
while (true) {
String input = sc.nextLine();
// we will check from 0 to the first space
// this will let us know of the command
String[] command = input.split(" ");
if (input.equals("bye")) {
// update the duke.txt file
ParseDukeTxt.updateDukeTxt(dataPath, tasks);
System.out.println(BYE);
break;
} else if (input.equals("list")) {
System.out.println(LINE_BREAK);
System.out.println(" " + LINE_INTRO);
int internalCounter = 1;
// iterate through the list
for (Task task : tasks) {
if (task != null) {
System.out.println(" " + internalCounter + ". " + task);
++internalCounter;
} else {
break;
}
}
} else if (command[0].equals("mark")) {
int number = Integer.parseInt(command[1]) - 1;
// Task currTask = list[number];
Task currTask = tasks.get(number);
boolean currState = currTask.getIsDone();
currTask.setDone(!currState);
System.out.println(LINE_BREAK);
System.out.println(" " + MARK_MESSAGE);
System.out.println(" [X] " + currTask.getDescription());
} else if (command[0].equals("unmark")) {
int number = Integer.parseInt(command[1]) - 1;
// Task currTask = list[number];
Task currTask = tasks.get(number);
boolean currState = currTask.getIsDone();
currTask.setDone(!currState);
System.out.println(LINE_BREAK);
System.out.println(" " + UNMARK_MESSAGE);
System.out.println(" [ ] " + currTask.getDescription());
} else if (command[0].equals("deadline")) {
// deadline make some cups /by the day after
if (command.length == 1) {
DukeException e = new DukeException("bro why la");
System.err.println(e.getMessage());
} else {
String[] deadlineInput = input.split("/by");
String deadline = deadlineInput[1];
String left = deadlineInput[0];
String description = left.substring(9, left.length() - 1);
// create a new deadline
Task newTask = new Deadlines(description, deadline);
// adding to the array
// list[counter] = newTask;
tasks.add(newTask);
++counter;
System.out.println(LINE_BREAK);
System.out
.println("Got it. I added this deadline already bro: \n" + " " + newTask.toString() + "\n");
System.out.println("Now you have " + counter + " tasks in the list. \n");
}
} else if (command[0].equals("event")) {
// event project meeting /at Mon 2-4pm
if (command.length == 1) {
DukeException e = new DukeException("OOPS!!! The description of an event cannot be empty.");
System.out.println(LINE_BREAK);
System.out.println(e.getMessage());
} else {
String[] deadlineInput = input.split("/at");
String deadline = deadlineInput[1];
String left = deadlineInput[0];
String description = left.substring(6, left.length() - 1);
// create a new deadline
Task newTask = new Events(description, deadline);
// adding to the array
// list[counter] = newTask;
tasks.add(newTask);
++counter;
System.out.println(LINE_BREAK);
System.out.println("Got it. I added this event already bro: \n" + " " + newTask.toString() + "\n");
System.out.println("Now you have " + counter + " tasks in the list. \n");
}
} else if (command[0].equals("todo")) {
// here we declare the new task to be added (TODO)
if (command.length == 1) {
DukeException e = new DukeException("โน OOPS!!! The description of a todo cannot be empty.");
System.out.println(LINE_BREAK);
System.out.println(e.getMessage());
} else {
Task t = new ToDos(input);
// list[counter] = t;
tasks.add(t);
System.out.println(LINE_BREAK);
System.out.println(" ok added alr bro: " + input);
++counter;
}
} else if (command[0].equals("delete")) {
// deleting a task
// find the index to be deleted
int number = Integer.parseInt(command[1]) - 1;
// task being deleted
Task beingDeleted = tasks.get(number);
// deleting operation
tasks.remove(number);
System.out.println("Noted. I've removed this task: ");
System.out.println(" " + beingDeleted);
System.out.println("Now you have " + tasks.size() + " in the list.");
} else {
DukeException e = new DukeException("Tak faham banggg, speak in my language la bayi....");
System.out.println(e.getMessage());
}
}
}
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/Deadlines.java
lines 13-15
:
/**
* Deadline will take in a description and a by timeline.
*/
Example from src/main/java/Duke.java
lines 30-35
:
/**
* Method to write to the duke.txt file.
*
* @param filePath path of the file to write to
* @param addText text we want to add to the file
*/
Example from src/main/java/Duke.java
lines 42-47
:
/**
* Method to append to the end of the present file.
*
* @param filePath path of the file to write to
* @param addText text we want to add to the file
*/
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 ๐
Aspect: Binary files in repo
Suggestion: Avoid committing binary files (e.g., *.class
, *.jar
, *.exe
) or third-party library files in to the repo.
โน๏ธ 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 [email protected]
if you want to follow up on this post.