rycs2812 / ip Goto Github PK
View Code? Open in Web Editor NEWThis project forked from nus-cs2103-ay2223s1/ip
This project forked from nus-cs2103-ay2223s1/ip
@rycs2812 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.
No easy-to-detect issues ๐
Example from src/main/java/duke/Task.java
lines 10-10
:
private boolean marked;
Suggestion: Follow the given naming convention for boolean variables/methods (e.g., use a boolean-sounding prefix).You may ignore the above if you think the name already follows the convention (the script can report false positives in some cases)
No easy-to-detect issues ๐
No easy-to-detect issues ๐
No easy-to-detect issues ๐
No easy-to-detect issues ๐
Example from src/main/java/duke/Command.java
lines 35-127
:
public void run(String args, Duke duke) {
UI ui = duke.getUI();
TaskList taskList = duke.getTaskList();
Storage storage = duke.getStorage();
if (!isCorrectUsage(args, duke)) {
return;
}
switch(name) {
case "delete":
int index = Integer.parseInt(args) - 1;
Task t = taskList.deleteTask(index);
ui.printTaskDeleted(t, taskList.getCount());
try {
storage.rewriteFile(taskList.getTasks());
} catch (IOException e) {
ui.printError("Unable to write to file.");
}
break;
case "find":
if (args.charAt(0) == '"' && args.charAt(args.length() - 1) == '"') {
args = args.substring(1, args.length() - 1);
}
ArrayList<Task> matchingTasks = taskList.getMatchingTasks(args);
if (matchingTasks.isEmpty()) {
ui.print("No results found for keyword '" + args + "'");
} else {
ui.printTasks(matchingTasks, "Here are the matching tasks in your list:");
}
break;
case "list":
ui.printTasks(duke.getTaskList().getTasks(), "Here are the tasks in your list:");
break;
case "deadline":
String[] temp = args.split(" /by ", 2);
t = new Deadline(temp[0], LocalDate.parse(temp[1],
DateTimeFormatter.ofPattern(INPUT_DATE_FORMAT)));
taskList.addTask(t);
ui.printTaskAdded(t, taskList.getCount());
try {
storage.appendTaskToFile(t);
} catch (IOException e) {
ui.printError("Unable to write to file.");
}
break;
case "event":
temp = args.split(" /at ", 2);
t = new Event(temp[0], LocalDate.parse(temp[1],
DateTimeFormatter.ofPattern(INPUT_DATE_FORMAT)));
taskList.addTask(t);
ui.printTaskAdded(t, taskList.getCount());
try {
storage.appendTaskToFile(t);
} catch (IOException e) {
ui.printError("Unable to write to file.");
}
break;
case "todo":
t = new ToDo(args);
taskList.addTask(t);
ui.printTaskAdded(t, taskList.getCount());
try {
storage.appendTaskToFile(t);
} catch (IOException e) {
ui.printError("Unable to write to file.");
}
break;
case "mark":
// Fallthrough
case "unmark":
index = Integer.parseInt(args) - 1;
t = taskList.getTasks().get(index);
boolean b = name.equals("mark");
taskList.markTask(t, b);
ui.printTaskMarked(t, b);
try {
storage.rewriteFile(taskList.getTasks());
} catch (IOException e) {
ui.printError("Unable to write to file.");
}
break;
default:
break;
}
}
Example from src/main/java/duke/Command.java
lines 138-231
:
private boolean isCorrectUsage(String args, Duke duke) {
UI ui = duke.getUI();
TaskList taskList = duke.getTaskList();
String usage = getCorrectUsage();
switch(name) {
case "delete":
if (args.isEmpty()) {
ui.printError("Please specify a task number.\n\n" + usage);
return false;
}
return true;
case "find":
if (args.isBlank()) {
ui.printError("Please specify at least one keyword.\n\n" + usage);
return false;
} else if (args.charAt(0) != '"' || args.charAt(args.length() - 1) != '"') {
if (args.split(" ").length > 1) {
ui.printError("'find' only expects 1 argument.\n\n If there are multiple "
+ "keywords, please enclose them in quotation marks (\"\").");
return false;
}
} else {
if (args.length() == 2 || args.substring(1, args.length() - 1).isBlank()) {
ui.printError("Please specify at least one keyword.\n\n" + usage);
return false;
}
}
return true;
case "list":
if (!args.isEmpty()) {
ui.printError("'list' expects no arguments.");
return false;
}
return true;
case "deadline":
String[] temp = args.split(" /by ", 2);
if (temp.length < 2) {
ui.printError("Please specify a task and deadline.\n\n" + usage);
return false;
} else if (!isValidDate(temp[1])) {
ui.printError("Please specify the due date in the right format.\n\n" + usage);
return false;
}
return true;
case "event":
temp = args.split(" /at ", 2);
if (temp.length < 2) {
ui.printError("Please specify an event and date.\n\n" + usage);
return false;
} else if (!isValidDate(temp[1])) {
ui.printError("Please specify the event date in the right format.\n\n" + usage);
return false;
}
return true;
case "todo":
if (args.isEmpty()) {
ui.printError("Please specify a task.\n\n" + usage);
return false;
}
return true;
case "mark":
// Fallthrough
case "unmark":
if (args.isEmpty()) {
ui.printError("Please specify a task number\n\n" + usage);
return false;
} else {
try {
int index = Integer.parseInt(args) - 1;
if (index < 0 || index >= taskList.getCount()) {
ui.printError("Please specify a valid task number.\n"
+ "There are " + taskList.getCount()
+ " task(s) in the list.\n\n" + usage);
return false;
}
return true;
} catch (NumberFormatException e) {
ui.printError("Please specify a task number.\n\n"
+ "\"" + args + "\"" + " is not an item number\n" + usage);
return false;
}
}
default:
return false;
}
}
Example from src/main/java/duke/Storage.java
lines 27-79
:
public ArrayList<Task> load() throws FileNotFoundException {
File f = new File(filePath);
f.getParentFile().mkdirs();
try {
if (!f.exists()) {
f.createNewFile();
}
} catch (IOException e) {
System.out.println("Unable to read file.");
}
ArrayList<Task> tasks = new ArrayList<>();
Scanner s = new Scanner(f);
while (s.hasNext()) {
String nextTask = s.nextLine();
String[] temp = nextTask.split("\\[");
Character taskType = temp[1].charAt(0);
Boolean marked = temp[2].charAt(0) == 'X';
String dateTemp = temp[temp.length - 1];
dateTemp = dateTemp.substring(0, dateTemp.length() - 1);
LocalDate date = LocalDate.now();
if (!dateTemp.isEmpty()) {
date = LocalDate.parse(dateTemp);
}
String task = "";
for (int i = 3; i < temp.length - 1; ++i) {
if (i < temp.length - 2) {
task += temp[i];
task += "[";
} else {
task += temp[i].substring(0, temp[i].length() - 1);
}
}
switch(taskType) {
case 'T':
addTask(tasks, new ToDo(task), marked);
break;
case 'D':
addTask(tasks, new Deadline(task, date), marked);
break;
case 'E':
addTask(tasks, new Event(task, date), marked);
break;
default:
break;
}
}
return tasks;
}
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.
No easy-to-detect issues ๐
No easy-to-detect issues ๐
No easy-to-detect issues ๐
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 [email protected]
if you want to follow up on this post.
@rycs2812 We did an automated analysis of your code to detect potential areas to improve the code quality. We are sharing the results below, so that you can avoid similar problems in your tP code (which will be graded more strictly for code quality).
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.
No easy-to-detect issues ๐
No easy-to-detect issues ๐
No easy-to-detect issues ๐
No easy-to-detect issues ๐
No easy-to-detect issues ๐
No easy-to-detect issues ๐
Example from src/main/java/duke/Command.java
lines 34-86
:
public String run(String args, Duke duke) {
String errorMessage = getUsageError(args, duke);
if (!errorMessage.isEmpty()) {
// If the command is used incorrectly
return errorMessage;
}
switch(name) {
case "delete":
int index = Integer.parseInt(args) - 1;
return duke.deleteTask(index);
case "find":
if (args.charAt(0) == '"' && args.charAt(args.length() - 1) == '"') {
args = args.substring(1, args.length() - 1);
}
return duke.findTask(args);
case "list":
return duke.listTasks();
case "deadline":
String[] temp = args.split(" /by ", 2);
String[] recurring = temp[1].split(" /every ", 2);
int period = getPeriod(temp[1]);
Task t = new Deadline(temp[0], LocalDate.parse(recurring[0].trim(),
DateTimeFormatter.ofPattern(INPUT_DATE_FORMAT)), period);;
return duke.addTask(t);
case "event":
temp = args.split(" /at ", 2);
recurring = temp[1].split(" /every ", 2);
period = getPeriod(temp[1]);
t = new Event(temp[0], LocalDate.parse(recurring[0].trim(),
DateTimeFormatter.ofPattern(INPUT_DATE_FORMAT)), period);
return duke.addTask(t);
case "todo":
t = new ToDo(args);
return duke.addTask(t);
case "mark":
// Fallthrough
case "unmark":
index = Integer.parseInt(args) - 1;
boolean b = name.equals("mark");
return duke.markTask(index, b);
default:
return "";
}
}
Example from src/main/java/duke/Command.java
lines 106-222
:
private String getUsageError(String args, Duke duke) {
TaskList taskList = duke.getTaskList();
String usage = getCorrectUsage();
String error = "ERROR: \n\n";
assert taskList != null : "Task list is null";
switch(name) {
case "delete":
if (args.isEmpty()) {
return error + "Please specify a task number.\n\n" + usage;
}
try {
int index = Integer.parseInt(args);
int count = taskList.getCount();
if (index <= 0 || index > taskList.getCount()) {
return error + "Please specify a valid task number. There are "
+ count + " tasks in the list\n\n" + usage;
}
} catch (NumberFormatException e) {
return error + "Please specify a task number.\n\n" + usage;
}
return "";
case "find":
if (args.isBlank()) {
return error + "Please specify at least one keyword.\n\n" + usage;
} else if (args.charAt(0) != '"' || args.charAt(args.length() - 1) != '"') {
if (args.split(" ").length > 1) {
return error + "'find' only expects 1 argument.\n\n If there are multiple "
+ "keywords, please enclose them in quotation marks (\"\").";
}
} else {
if (args.length() == 2 || args.substring(1, args.length() - 1).isBlank()) {
return error + "Please specify at least one keyword.\n\n" + usage;
}
}
return "";
case "list":
if (!args.isEmpty()) {
return error + "'list' expects no arguments.";
}
return "";
case "deadline":
String[] temp = args.split(" /by ", 2);
if (temp.length < 2) {
return error + "Please specify a task and deadline.\n\n" + usage;
} else {
String[] recurring = temp[1].split(" /every ", 2);
int period = getPeriod(temp[1]);
if (period < 0) {
return error + "Please specify a valid period for recurring tasks.\n\n" + usage;
} else if (period == 0) {
if (!isValidDate(temp[1])) {
return error + "Please specify the due date in the right format.\n\n" + usage;
}
}
if (!isValidDate(recurring[0])) {
return error + "Please specify the due date in the right format.\n\n" + usage;
}
}
return "";
case "event":
temp = args.split(" /at ", 2);
if (temp.length < 2) {
return error + "Please specify an event and date.\n\n" + usage;
} else {
String[] recurring = temp[1].split(" /every ", 2);
int period = getPeriod(temp[1]);
if (period < 0) {
return error + "Please specify a valid period for recurring tasks.\n\n" + usage;
} else if (period == 0) {
if (!isValidDate(temp[1])) {
return error + "Please specify the event date in the right format.\n\n" + usage;
}
}
if (!isValidDate(recurring[0])) {
return error + "Please specify the due date in the right format.\n\n" + usage;
}
}
return "";
case "todo":
if (args.isEmpty()) {
return error + "Please specify a task.\n\n" + usage;
}
return "";
case "mark":
// Fallthrough
case "unmark":
if (args.isEmpty()) {
return error + "Please specify a task number\n\n" + usage;
} else {
try {
int index = Integer.parseInt(args) - 1;
if (index < 0 || index >= taskList.getCount()) {
return error + "Please specify a valid task number.\n"
+ "There are " + taskList.getCount()
+ " task(s) in the list.\n\n" + usage;
}
} catch (NumberFormatException e) {
return error + "Please specify a task number.\n"
+ "\"" + args + "\"" + " is not a task number\n\n" + usage;
}
}
return "";
default:
return "";
}
}
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.
No easy-to-detect issues ๐
No easy-to-detect issues ๐
No easy-to-detect issues ๐
No easy-to-detect issues ๐
โ You are not required to (but you are welcome to) fix the above problems in your iP, unless you have been separately asked to resubmit the iP due to code quality 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 [email protected]
if you want to follow up on this post.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.