-
Notifications
You must be signed in to change notification settings - Fork 77
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
[Abhitya Krishnaraj] iP #65
base: master
Are you sure you want to change the base?
[Abhitya Krishnaraj] iP #65
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other then some spacing and naming issues, looks good to me!
src/main/java/Deadline.java
Outdated
|
||
public class Deadline extends Task{ | ||
protected String date; | ||
public Deadline(String n, boolean d, String dat){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add spaces between binary operators and their operands "[D]" + super.toString() + " (by: " + date + ")"
src/main/java/Duke.java
Outdated
|
||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Single comment for whole file:
- Consider not shortening variable names, especially if its already short enough < 8 chars
inp
,comm
,tas
requires 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as other file, consider adding spaces between operands and binary operators
super(n, d); | ||
} | ||
public String toString(){ | ||
return "[T]"+super.toString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above, add spaces
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add space between Class name and bracket
src/main/java/Deadline.java
Outdated
|
||
public class Deadline extends Task{ | ||
protected String date; | ||
public Deadline(String n, boolean d, String dat){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add space between function name and bracket
src/main/java/Duke.java
Outdated
System.out.println("What can I do for you"); | ||
String inp = in.nextLine(); | ||
ArrayList<Task> list = new ArrayList<>(); | ||
while(!inp.equals("bye")){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add space
src/main/java/Duke.java
Outdated
String inp = in.nextLine(); | ||
ArrayList<Task> list = new ArrayList<>(); | ||
while(!inp.equals("bye")){ | ||
if(inp.equals("list")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add space after if
} | ||
} | ||
|
||
public String toString() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should add @OverRide
public Todo(String n, boolean d){ | ||
super(n, d); | ||
} | ||
public String toString(){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should override the to String function in Task
src/main/java/Task.java
Outdated
public Task(String n, boolean d) { | ||
name = n; | ||
isDone = d; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public Task(String name, boolean isDone) {
this.name = name;
this.isDone = isDone;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some parts could be improved. Please pay more attention to SLAP and separation of concerns.
src/main/Duke.java
Outdated
@@ -0,0 +1,206 @@ | |||
package main; | |||
|
|||
import java.io.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Coding Standard Violation] Imported classes should always be listed explicitly.
src/main/Duke.java
Outdated
import java.io.*; | ||
import java.nio.file.Paths; | ||
import java.nio.file.Path; | ||
import java.util.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Coding Standard Violation] Imported classes should always be listed explicitly.
src/main/Duke.java
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Code Quality] Consider extracting UI-related constructs to a dedicated class.
src/main/Duke.java
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Code Quality] inp
is not very friendly, consider changing the variable name.
Tip: use intention-revealing name.
src/main/Duke.java
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[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.
src/main/Duke.java
Outdated
try{ | ||
if(!(f.createNewFile())){ | ||
f.delete(); | ||
f = new File("docs/duke.txt"); | ||
} | ||
} | ||
catch(IOException e){ | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Code Quality] The try-catch
here is unnecessary. Try to figure out why?
src/main/Duke.java
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Code Quality] Again, the method fileToList
seems to be a utility function. Consider extracting it out.
src/main/Duke.java
Outdated
@@ -0,0 +1,206 @@ | |||
package main; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
Duke
is not very good, e.g. unrelated static methods, SLAP is lacking, readability issues.
src/main/DukeException.java
Outdated
} | ||
public void printError() { | ||
if (name.equals("")){ | ||
if (type.equals("todo")||type.equals("deadline")||type.equals("event")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Code Quality] Consider extracting out this complicated expression.
src/main/Event.java
Outdated
|
||
public class Event extends Task{ | ||
protected String date; | ||
public Event(String n, boolean d, String dat){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Code Quality] Consider renaming the method parameters.
Level-9 Merge pull request from branch
branch-A-JavaDoc
No description provided.