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

[Abhitya Krishnaraj] iP #65

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

Conversation

abhityakrishnaraj
Copy link

No description provided.

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

@winston-lim winston-lim left a 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!


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

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

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


System.out.println("Hello! I'm Duke");
System.out.println("What can I do for you");
String inp = in.nextLine();

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

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

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

Copy link

@bdthanh bdthanh left a 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{
Copy link

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


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

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

System.out.println("What can I do for you");
String inp = in.nextLine();
ArrayList<Task> list = new ArrayList<>();
while(!inp.equals("bye")){
Copy link

Choose a reason for hiding this comment

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

Add space

String inp = in.nextLine();
ArrayList<Task> list = new ArrayList<>();
while(!inp.equals("bye")){
if(inp.equals("list")) {
Copy link

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() {
Copy link

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(){
Copy link

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 on lines 12 to 15
public Task(String n, boolean d) {
name = n;
isDone = d;
}
Copy link

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

Copy link

@richwill28 richwill28 left a 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.

@@ -0,0 +1,206 @@
package main;

import java.io.*;

Choose a reason for hiding this comment

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

import java.io.*;
import java.nio.file.Paths;
import java.nio.file.Path;
import java.util.*;

Choose a reason for hiding this comment

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

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

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.

System.out.println("Hello! I'm Duke");
System.out.println("What can I do for you");
fileToList();
String inp = in.nextLine();

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

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 on lines 137 to 145
try{
if(!(f.createNewFile())){
f.delete();
f = new File("docs/duke.txt");
}
}
catch(IOException e){

}

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

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.

@@ -0,0 +1,206 @@
package main;

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

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.


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

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