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 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 24-24
:
// System.out.println(file.mkdir());
Example from src/main/java/Duke.java
lines 53-53
:
// System.out.println(data);
Example from src/main/java/Duke.java
lines 87-87
:
// arr.get(task).markAsDone();
Suggestion: Remove dead code from the codebase.
Aspect: Method Length
Example from src/main/java/Duke.java
lines 8-273
:
public static void main(String[] args) {
List<Task> arr = new ArrayList<>();
int count = 0;
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
String greeting = "____________________________________________________________\n" +
"Hello! I'm Duke\n" +
"What can I do for you?\n" +
"____________________________________________________________\n";
System.out.println(greeting);
File folder = new File("data");
folder.mkdir();
// System.out.println(file.mkdir());
File file = new File(folder, "duke.txt");
try {
file.createNewFile();
} catch (IOException e) {
System.out.println(e);
}
Scanner myObj = new Scanner(System.in);
while (true) {
String input = myObj.nextLine();
if (input.equals("bye")) {
String bye = "____________________________________________________________\n" +
"Bye. Hope to see you again soon!\n" +
"____________________________________________________________";
System.out.println(bye);
return;
} else if (input.equals("list")) {
System.out.println("____________________________________________________________");
System.out.println("Here are the tasks in your list:");
/*
for (int i = 0; i < count; i++) {
System.out.println(" " + (i + 1) + "." + arr.get(i).toString());
}*/
try {
Scanner reader = new Scanner(file);
int n = 0;
while (reader.hasNextLine()) {
String data = reader.nextLine();
// System.out.println(data);
String[] parsed = data.split(" \\| ");
String type = parsed[0];
String description = parsed[2];
n++;
if (type.equals("T")) {
Todo todo = new Todo(description);
if (parsed[1].equals("1")) {
todo.markAsDone();
}
System.out.println(" " + (n) + "." + todo.toString());
} else if (type.equals("D")) {
Deadline deadline = new Deadline(description, LocalDate.parse(parsed[3]));
if (parsed[1].equals("1")) {
deadline.markAsDone();
}
System.out.println(" " + (n) + "." + deadline.toString());
} else if (type.equals("E")) {
Event event = new Event(description, LocalDate.parse(parsed[3]));
if (parsed[1].equals("1")) {
event.markAsDone();
}
System.out.println(" " + (n) + "." + event.toString());
}
}
} catch (FileNotFoundException e) {
System.out.println(e);
}
System.out.println("____________________________________________________________");
} else if (input.startsWith("done ")) {
int task = Integer.parseInt(input.split(" ")[1]);
int n = 0;
// arr.get(task).markAsDone();
try {
Scanner reader = new Scanner(file);
List<String> lines = new ArrayList<>();
while (reader.hasNextLine()) {
n++;
String data = reader.nextLine();
if (task == n) {
String update = data.substring(0,4)+'1'+data.substring(5);
// System.out.println(update);
// System.out.println(data);
lines.add(update);
} else {
lines.add(data);
}
/*
System.out.println("____________________________________________________________");
System.out.println("Nice! I've marked this task as done:");
System.out.println(" " + arr.get(task).toString());
System.out.println("____________________________________________________________");
*/
// mark as done
}
file.delete();
try {
file.createNewFile();
PrintWriter writer = new PrintWriter(file);
for (String line : lines) {
writer.println(line);
}
writer.close();
} catch (IOException e) {
System.out.println(e);
}
} catch (FileNotFoundException e) {
System.out.println(e);
}
} else if (input.startsWith("todo")) {
try {
if (input.split(" ").length == 1) {
throw new DukeException("____________________________________________________________\n" +
"โน OOPS!!! The description of a todo cannot be empty.\n" +
"____________________________________________________________");
}
String task = input.split(" ")[1];
Todo todo = new Todo(task);
// arr.add(new Todo(task));
try {
Scanner reader = new Scanner(file);
List<String> lines = new ArrayList<>();
while (reader.hasNextLine()) {
String data = reader.nextLine();
lines.add(data);
}
file.delete();
try {
file.createNewFile();
PrintWriter writer = new PrintWriter(file);
for (String line : lines) {
writer.println(line);
}
writer.println(todo.addToFile());
writer.close();
} catch (IOException e) {
System.out.println(e);
}
} catch (FileNotFoundException e) {
System.out.println(e);
}
count++;
String s = "";
if (count > 1 && count != 0) {
s = "s";
}
String reply = "____________________________________________________________\n" +
"Got it. I've added this task:\n " +
todo.toString() + "\n" +
"Now you have " + count + " task" + s + " in the list.\n" +
"____________________________________________________________";
System.out.println(reply);
} catch (DukeException e) {
System.out.println(e);
}
} else if (input.startsWith("deadline")) {
String[] n = input.split(" ", 2)[1].split(" /by ");
// arr.add(new Deadline(n[0], n[1]));
String task = n[0];
LocalDate time = LocalDate.parse(n[1]);
Deadline deadline = new Deadline(task, time);
try {
Scanner reader = new Scanner(file);
List<String> lines = new ArrayList<>();
while (reader.hasNextLine()) {
String data = reader.nextLine();
lines.add(data);
}
file.delete();
try {
file.createNewFile();
PrintWriter writer = new PrintWriter(file);
for (String line : lines) {
writer.println(line);
}
writer.println(deadline.addToFile());
writer.close();
} catch (IOException e) {
System.out.println(e);
}
} catch (FileNotFoundException e) {
System.out.println(e);
}
count++;
String s = "";
if (count > 1 && count != 0) {
s = "s";
}
String reply = "____________________________________________________________\n" +
"Got it. I've added this task:\n " +
deadline.toString() + "\n" +
"Now you have " + count + " task" + s + " in the list.\n" +
"____________________________________________________________";
System.out.println(reply);
} else if (input.startsWith("event")) {
String[] n = input.split(" ", 2)[1].split(" /at ");
// arr.add(new Event(n[0], n[1]));
String task = n[0];
LocalDate time = LocalDate.parse(n[1]);
Event event = new Event(task, time);
try {
Scanner reader = new Scanner(file);
List<String> lines = new ArrayList<>();
while (reader.hasNextLine()) {
String data = reader.nextLine();
lines.add(data);
}
file.delete();
try {
file.createNewFile();
PrintWriter writer = new PrintWriter(file);
for (String line : lines) {
writer.println(line);
}
writer.println(event.addToFile());
writer.close();
} catch (IOException e) {
System.out.println(e);
}
} catch (FileNotFoundException e) {
System.out.println(e);
}
count++;
String s = "";
if (count > 1 && count != 0) {
s = "s";
}
String reply = "____________________________________________________________\n" +
"Got it. I've added this task:\n " +
event.toString() + "\n" +
"Now you have " + count + " task" + s + " in the list.\n" +
"____________________________________________________________";
System.out.println(reply);
} else if (input.startsWith("delete")) {
int pos = Integer.parseInt(input.split(" ")[1]);
Task task = arr.get(pos-1);
arr.remove(pos-1);
count--;
String s = "";
if (count > 1 && count != 0) {
s = "s";
}
String reply = "____________________________________________________________\n" +
"Noted. I've removed this task:\n " +
task + "\n" +
"Now you have " + count + " task" + s + " in the list.\n" +
"____________________________________________________________";
System.out.println(reply);
} else {
System.out.println(new DukeException("____________________________________________________________\n" +
"โน OOPS!!! I'm sorry, but I don't know what that means :-(\n" +
"____________________________________________________________"));
}
}
}
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: Header Comments
No easy-to-detect issues ๐
Aspect: Recent Git Commit Message (Subject Only)
possible problems in commit 4a0dbbb
:
test
possible problems in commit aa2c055
:
Level-8
possible problems in commit 5c22aee
:
Level-8
Suggestion: Follow the given conventions for Git commit messages
โน๏ธ 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 [email protected]
if you want to follow up on this post.