[Abhitya Krishnaraj] iP#65
Conversation
winston-lim
left a comment
There was a problem hiding this comment.
Other then some spacing and naming issues, looks good to me!
|
|
||
| public class Deadline extends Task{ | ||
| protected String date; | ||
| public Deadline(String n, boolean d, String dat){ |
There was a problem hiding this comment.
Consider having more semantically meaningful name for parameters
|
|
||
| @Override | ||
| public String toString() { | ||
| return "[D]"+super.toString()+" (by: "+date+")"; |
There was a problem hiding this comment.
Add spaces between binary operators and their operands "[D]" + super.toString() + " (by: " + date + ")"
|
|
||
| System.out.println("Hello! I'm Duke"); | ||
| System.out.println("What can I do for you"); | ||
| String inp = in.nextLine(); |
There was a problem hiding this comment.
Single comment for whole file:
- Consider not shortening variable names, especially if its already short enough < 8 chars
inp,comm,tasrequires context to understand so it may be better to leave them as is or name differently
|
|
||
| @Override | ||
| public String toString() { | ||
| return "[E]"+super.toString()+" (at: "+date+")"; |
There was a problem hiding this comment.
Same as other file, consider adding spaces between operands and binary operators
| super(n, d); | ||
| } | ||
| public String toString(){ | ||
| return "[T]"+super.toString(); |
bdthanh
left a comment
There was a problem hiding this comment.
To add space, you can use shortcut Ctrl + Alt + L
| @@ -0,0 +1,14 @@ | |||
| package main.java; | |||
|
|
|||
| public class Deadline extends Task{ | |||
There was a problem hiding this comment.
Add space between Class name and bracket
|
|
||
| public class Deadline extends Task{ | ||
| protected String date; | ||
| public Deadline(String n, boolean d, String dat){ |
There was a problem hiding this comment.
Add space between function name and bracket
| System.out.println("What can I do for you"); | ||
| String inp = in.nextLine(); | ||
| ArrayList<Task> list = new ArrayList<>(); | ||
| while(!inp.equals("bye")){ |
| String inp = in.nextLine(); | ||
| ArrayList<Task> list = new ArrayList<>(); | ||
| while(!inp.equals("bye")){ | ||
| if(inp.equals("list")) { |
| } | ||
| } | ||
|
|
||
| public String toString() { |
| public Todo(String n, boolean d){ | ||
| super(n, d); | ||
| } | ||
| public String toString(){ |
There was a problem hiding this comment.
Should override the to String function in Task
| public Task(String n, boolean d) { | ||
| name = n; | ||
| isDone = d; | ||
| } |
There was a problem hiding this comment.
public Task(String name, boolean isDone) {
this.name = name;
this.isDone = isDone;
}
richwill28
left a comment
There was a problem hiding this comment.
Some parts could be improved. Please pay more attention to SLAP and separation of concerns.
| @@ -0,0 +1,206 @@ | |||
| package main; | |||
|
|
|||
| import java.io.*; | |||
There was a problem hiding this comment.
[Coding Standard Violation] Imported classes should always be listed explicitly.
| import java.io.*; | ||
| import java.nio.file.Paths; | ||
| import java.nio.file.Path; | ||
| import java.util.*; |
There was a problem hiding this comment.
[Coding Standard Violation] Imported classes should always be listed explicitly.
| String logo = " ____ _ \n" | ||
| + "| _ \\ _ _| | _____ \n" | ||
| + "| | | | | | | |/ / _ \\\n" | ||
| + "| |_| | |_| | < __/\n" | ||
| + "|____/ \\__,_|_|\\_\\___|\n"; | ||
| System.out.println("Hello from\n" + logo); | ||
|
|
||
| System.out.println("Hello! I'm Duke"); | ||
| System.out.println("What can I do for you"); |
There was a problem hiding this comment.
[Code Quality] Consider extracting UI-related constructs to a dedicated class.
| System.out.println("Hello! I'm Duke"); | ||
| System.out.println("What can I do for you"); | ||
| fileToList(); | ||
| String inp = in.nextLine(); |
There was a problem hiding this comment.
[Code Quality] inp is not very friendly, consider changing the variable name.
Tip: use intention-revealing name.
| while(!inp.equals("bye")){ | ||
| if(inp.equals("list")) { | ||
| for (int i = 1; i <= list.size(); i++) { | ||
| System.out.print(i + ". "); | ||
| System.out.println(list.get(i - 1)); | ||
| } | ||
| } | ||
| else if (inp.contains("mark")){ | ||
| int num = Integer.parseInt(inp.substring(inp.indexOf(" ")+1))-1; | ||
| if(num>list.size()){ | ||
| System.out.println("Out of bounds of the list"); | ||
| } | ||
| else{ | ||
| if(inp.contains("unmark")){ | ||
| System.out.println("I have marked this task as not done yet"); | ||
| list.get(num).setDone(false); | ||
| } | ||
| else{ | ||
| System.out.println("I have marked this task as complete"); | ||
| list.get(num).setDone(true); | ||
| } | ||
| System.out.println(list.get(num)); | ||
| listToFile(); | ||
| } | ||
|
|
||
| } | ||
| else if(inp.contains("delete")){ | ||
| int num = Integer.parseInt(inp.substring(inp.indexOf(" ")+1))-1; | ||
| if(num>list.size()){ | ||
| System.out.println("Out of bounds of the list"); | ||
| } | ||
| else{ | ||
| System.out.println("I have removed this task: "); | ||
| System.out.println(list.get(num)); | ||
| list.remove(num); | ||
| System.out.println("You now have "+list.size()+" tasks left in the list."); | ||
| listToFile(); | ||
| } | ||
| } | ||
| else { | ||
| try{ | ||
| taskReader(inp); | ||
| listToFile(); | ||
| } | ||
| catch (DukeException e){ | ||
| e.printError(); | ||
| } | ||
| } | ||
| inp = in.nextLine(); | ||
| } |
There was a problem hiding this comment.
[Code Quality] This whole section is hard to read and reason about.
The first rule of functions is that they should be small. The second rule of functions is that they should be smaller than that.
Tip: extract the entire logic to a dedicated Parser class.
| try{ | ||
| if(!(f.createNewFile())){ | ||
| f.delete(); | ||
| f = new File("docs/duke.txt"); | ||
| } | ||
| } | ||
| catch(IOException e){ | ||
|
|
||
| } |
There was a problem hiding this comment.
[Code Quality] The try-catch here is unnecessary. Try to figure out why?
| public static void fileToList(){ | ||
|
|
||
| File f = new File("docs/duke.txt"); | ||
|
|
||
| try{ | ||
| if(!(f.createNewFile())){ | ||
| Scanner sc = new Scanner(f); | ||
| while(sc.hasNextLine()) { | ||
| String line = sc.nextLine(); | ||
| String[] lin = line.split(","); | ||
| Boolean temp; | ||
| temp = lin[1].equals("True"); | ||
| if(lin[0].equals("T")){ | ||
| list.add(new Todo(lin[2], temp)); | ||
| } | ||
| else if(lin[0].equals("D")){ | ||
| list.add(new Deadline(lin[2], temp, lin[4])); | ||
| } | ||
| else if(lin[0].equals("E")){ | ||
| list.add(new Event(lin[2], temp, lin[4])); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| catch (IOException e){ | ||
| System.out.println("Problem occurred with the file"); | ||
| } | ||
| } |
There was a problem hiding this comment.
[Code Quality] Again, the method fileToList seems to be a utility function. Consider extracting it out.
| @@ -0,0 +1,206 @@ | |||
| package main; | |||
There was a problem hiding this comment.
Duke.java
- There are several coding standard violations that I did not point out. Please refer to https://se-education.org/guides/conventions/java/index.html.
- Overall, the design for class
Dukeis not very good, e.g. unrelated static methods, SLAP is lacking, readability issues.
| } | ||
| public void printError() { | ||
| if (name.equals("")){ | ||
| if (type.equals("todo")||type.equals("deadline")||type.equals("event")) { |
There was a problem hiding this comment.
[Code Quality] Consider extracting out this complicated expression.
|
|
||
| public class Event extends Task{ | ||
| protected String date; | ||
| public Event(String n, boolean d, String dat){ |
There was a problem hiding this comment.
[Code Quality] Consider renaming the method parameters.
Level-9 Merge pull request from branch
branch-A-JavaDoc
No description provided.