Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iP #187

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open

iP #187

wants to merge 50 commits into from

Conversation

pragyan01
Copy link

Added levels 0-3 and A-CodingStandard

Copy link

@glenn-tck glenn-tck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only 1 minor coding violation found above, but I really like how neat and tidy your code is

System.out.println("\nNow you have " + taskCount + " tasks in the list.\n" + line);
}

//Filters user inputs and pushes to different methods

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No coding violations found here, I like the use of comments at the top to give a brief explanation of what the function does

public static void sayList() {
System.out.println(line);
for (int i = 0; i < taskCount; i++) {
System.out.println((i + 1) + ". " + t[i].toString()+ "\n");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the + between t[i].toString() and "\n" needs to have a spacing in between

public static String line = "------------------------------------------------------------------------------------------\n";

//declare task array and keep track of how many tasks stored
public static Task[] t = new Task[100];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No coding violations found, but maybe you can declare 100 as a constant to indicate that it is the maximum size of the list.

int endIndex = input.lastIndexOf("/");
String taskName = input.substring(9, endIndex);
int endIndex2 = input.length();
String by = input.substring(endIndex + 4, endIndex2);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No coding violation found, but I feel like it would be good if you declared the 4 here, 9 above in taskName and 5 above in the previous taskName as constants to make it apparent that these are offsets

//Adds a new todo task and prints it //todo borrow book
public static void sayTodo(String input) {
int endIndex = input.length();
String taskName = input.substring(5, endIndex);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

magic int. should use a constant instead of "5".

}

//Adds a new deadline task and prints it
public static void sayDeadline(String input) { //deadline return book /by Sunday

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method can be split into a few different methods. "sayDeadline" seems to imply printing like in sayBye() but also performs the adding of a new deadline object

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same with sayTodo() and sayEvent()

public static void sayEvent(String input) { //event project meeting /at Mon 2-4pm
int endIndex = input.lastIndexOf("/");
String taskName = input.substring(6, endIndex);
int endIndex2 = input.length();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name endIndex and endIndex2 differently to explain what the variables are/do

Copy link

@zikunz zikunz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work Pragyan! I can tell that you have definitely followed various coding guidelines and your Duke is so awesome! 💯

Overall, this version of code is very easy to understand and very readable. Please take some time to fix some very few potential and minor coding standard and quality-related problems and then it should be good to go. Keep up the good work :)

@@ -0,0 +1,25 @@
package duke;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great to see that you organise your types (e.g., classes) into a package for easier management!

Comment on lines 10 to 12
//declarations
public static String line = "------------------------------------------------------------------------------------------\n";
private static int quitFlag = 0; //if 0, take user input. Otherwise, don't.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 11 and 12 are quite obvious and self-explanatory, perhaps you could refrain from repeating the description in a comment.

import java.nio.file.StandardOpenOption;
import java.util.Scanner;
import java.util.ArrayList;
import java.io.*;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps you could avoid using a wildcard in the import statement by configuring your IDE to make all imported classes to be listed explicitly.


public class Duke {
//declarations
public static String line = "------------------------------------------------------------------------------------------\n";
Copy link

@zikunz zikunz Sep 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps you could make line final if it does not change, and change the naming accordingly (i.e., LINE).


//Saves Task list into local file
public static void saveData(ArrayList<Task> t) {
String path = "D:\\Documents\\NUS\\Y2S1\\CS2113T\\IP\\UserData.txt";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps you could use a relative path here rather than an absolute path because your app might cause unpredictable results when used in another computer.

}

//Program exits with this ending
public static void sayBye(String input) throws DukeException{ //bye
Copy link

@zikunz zikunz Sep 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps you could leave a space here before { for layout consistency.

Comment on lines 47 to 88
//Loads Task list into Duke
public static void loadData() throws FileNotFoundException, DukeException {
File f = new File("D:\\Documents\\NUS\\Y2S1\\CS2113T\\IP\\UserData.txt");

Scanner scan = new Scanner(f);
String taskType;
String s;
int taskNumber = 1; //tracks how many tasks read from .txt file so far

while(scan.hasNext()) //todo hello | 1
{ //deadline hello /by Sunday | 1
String data = scan.nextLine(); //event project meeting /at Mon 2-4pm | 0
String[] arrayString = data.split(" \\| ");
String[] arrayString2 = arrayString[0].split(" ");
taskType = arrayString2[0];
s = Integer.toString(taskNumber);

switch (taskType) {
case "todo":
sayTodo(arrayString[0]);
if (arrayString[1].equals("1")) {
sayDone(s);
}
break;
case "deadline":
sayDeadline(arrayString[0]);
if (arrayString[1].equals("1")) {
sayDone(s);
}
break;
case "event":
sayEvent(arrayString[0]);
if (arrayString[1].equals("1")) {
sayDone(s);
}
break;
default:
}
taskNumber++;
}
scan.close();
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method exceeds 30 LOC, perhaps you could shorten it (e.g., by extracting lines 64 to lines 84 into a method on its own).

Comment on lines 235 to 251
saveData(t);
break;
case "todo":
sayTodo(input);
saveData(t);
break;
case "deadline":
sayDeadline(input);
saveData(t);
break;
case "event":
sayEvent(input);
saveData(t);
break;
case "delete": //lvl 7
sayDelete(input);
saveData(t);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the "saveData(t)" is repeated mutiple times under different case statements, you could consider calling it only once to avoid repetitive code.

Comment on lines 259 to 264
//Main
public static void main(String[] args) throws DukeException, IOException {
start();
inputSort();
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All statements here are at the same level of abstraction, great! You have followed of Single Level of Abstraction Principle (SLAP) very well!

Comment on lines 56 to 58
while(scan.hasNext()) //todo hello | 1
{ //deadline hello /by Sunday | 1
String data = scan.nextLine(); //event project meeting /at Mon 2-4pm | 0
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps you could rewrite your while loop as per https://se-education.org/guides/conventions/java/index.html#layout so that { appear as the same line as while().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants