Skip to content

[Abhitya Krishnaraj] iP#65

Open
abhityakrishnaraj wants to merge 20 commits into
nus-cs2113-AY2223S1:masterfrom
abhityakrishnaraj:master
Open

[Abhitya Krishnaraj] iP#65
abhityakrishnaraj wants to merge 20 commits into
nus-cs2113-AY2223S1:masterfrom
abhityakrishnaraj:master

Conversation

@abhityakrishnaraj

Copy link
Copy Markdown

No description provided.

@abhityakrishnaraj abhityakrishnaraj changed the title Abhitya Krishnaraj iP [Abhitya Krishnaraj] iP Aug 30, 2022

@winston-lim winston-lim left a comment

Copy link
Copy Markdown

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!

Comment thread src/main/java/Deadline.java Outdated

public class Deadline extends Task{
protected String date;
public Deadline(String n, boolean d, String dat){

Copy link
Copy Markdown

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+")";

Copy link
Copy Markdown

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 + ")"

Comment thread 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();

Copy link
Copy Markdown

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

Comment thread src/main/java/Event.java

@Override
public String toString() {
return "[E]"+super.toString()+" (at: "+date+")";

Copy link
Copy Markdown

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

Comment thread src/main/java/Todo.java
super(n, d);
}
public String toString(){
return "[T]"+super.toString();

Copy link
Copy Markdown

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

@bdthanh bdthanh left a comment

Copy link
Copy Markdown

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{

Copy link
Copy Markdown

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

Comment thread src/main/java/Deadline.java Outdated

public class Deadline extends Task{
protected String date;
public Deadline(String n, boolean d, String dat){

Copy link
Copy Markdown

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

Comment thread 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")){

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Add space

Comment thread src/main/java/Duke.java Outdated
String inp = in.nextLine();
ArrayList<Task> list = new ArrayList<>();
while(!inp.equals("bye")){
if(inp.equals("list")) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Add space after if

Comment thread src/main/java/Task.java
}
}

public String toString() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Should add @OverRide

Comment thread src/main/java/Todo.java
public Todo(String n, boolean d){
super(n, d);
}
public String toString(){

Copy link
Copy Markdown

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

Comment thread src/main/java/Task.java Outdated
Comment on lines +12 to +15
public Task(String n, boolean d) {
name = n;
isDone = d;
}

Copy link
Copy Markdown

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;
}

@richwill28 richwill28 left a comment

Copy link
Copy Markdown

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.

Comment thread src/main/Duke.java Outdated
@@ -0,0 +1,206 @@
package main;

import java.io.*;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment thread src/main/Duke.java Outdated
import java.io.*;
import java.nio.file.Paths;
import java.nio.file.Path;
import java.util.*;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment thread src/main/Duke.java Outdated
Comment on lines +11 to +19
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");

Copy link
Copy Markdown

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.

Comment thread 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();

Copy link
Copy Markdown

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.

Comment thread src/main/Duke.java Outdated
Comment on lines +22 to +71
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();
}

Copy link
Copy Markdown

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.

Comment thread src/main/Duke.java Outdated
Comment on lines +137 to +145
try{
if(!(f.createNewFile())){
f.delete();
f = new File("docs/duke.txt");
}
}
catch(IOException e){

}

Copy link
Copy Markdown

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?

Comment thread src/main/Duke.java Outdated
Comment on lines +178 to +205
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");
}
}

Copy link
Copy Markdown

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.

Comment thread src/main/Duke.java Outdated
@@ -0,0 +1,206 @@
package main;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Duke.java

}
public void printError() {
if (name.equals("")){
if (type.equals("todo")||type.equals("deadline")||type.equals("event")) {

Copy link
Copy Markdown

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.

Comment thread src/main/Event.java Outdated

public class Event extends Task{
protected String date;
public Event(String n, boolean d, String dat){

Copy link
Copy Markdown

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.

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