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

[Rawal Aarav] iP #172

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

Conversation

aaravrawal52
Copy link

No description provided.

@aaravrawal52 aaravrawal52 changed the title IP [Rawal Aarav] iP Feb 7, 2024
import java.util.List;
import java.util.Scanner;

public class G_one {

Choose a reason for hiding this comment

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

the public class G_one should be named using PacalCase ( gOne/GOne)

@@ -0,0 +1,132 @@
import java.util.ArrayList;

Choose a reason for hiding this comment

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

Good listing of imported classes explicitly.

System.out.println("OK, I've marked this task as not done yet:");
System.out.println(" " + task);
} else {
System.out.println("Invalid task number.");

Choose a reason for hiding this comment

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

good use of error handling

G_one g_one = new G_one();
g_one.start();
}
}

Choose a reason for hiding this comment

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

perhaps you could add some comments to make your code easier to understand :)

System.out.println("Hello! I'm G.one");
System.out.println("--------------------------------------");
Scanner scanner = new Scanner(System.in);
boolean flag = true;
Copy link

Choose a reason for hiding this comment

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

Should this Boolean variable be named to sound like booleans? eg. isRunning etc

}

System.out.println("Goodbye!");
scanner.close();
Copy link

Choose a reason for hiding this comment

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

Very nice detail to close scanner in order to indicate that you're done with its underlying stream!

Comment on lines 12 to 30
public void start() {
System.out.println("Hello! I'm G.one");
System.out.println("--------------------------------------");

Scanner scanner = new Scanner(System.in);
boolean flag = true;

while (flag) {
System.out.print("Whats up? ");
String userInput = scanner.nextLine();

if (userInput.equalsIgnoreCase("bye")) {
flag = false;
} else if (userInput.equalsIgnoreCase("list")) {
displayTaskList();
} else {
processUserInput(userInput);
}
}
Copy link

Choose a reason for hiding this comment

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

Very good use of K&R style brackets!

@@ -0,0 +1,13 @@
public class DeadlineTask extends Task {
Copy link

Choose a reason for hiding this comment

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

Great that DeadlineTask Class name is a noun and written in PascalCase!

}

private void addEventTask(String descriptionAndTime) {
String[] parts = descriptionAndTime.split(" /from ");
Copy link

Choose a reason for hiding this comment

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

Good that array specifiers are attached to the type not the variable!

Comment on lines 37 to 51
if (userInput.startsWith("todo")) {
addTodoTask(userInput.substring(5).trim());
} else if (userInput.startsWith("deadline")) {
addDeadlineTask(userInput.substring(9).trim());
} else if (userInput.startsWith("event")) {
addEventTask(userInput.substring(6).trim());
} else if (userInput.startsWith("mark")) {
markTask(userInput.substring(5).trim());
} else if (userInput.startsWith("unmark")) {
unmarkTask(userInput.substring(7).trim());
} else if (userInput.equalsIgnoreCase("list")) {
displayTaskList();
} else {
System.out.println("Invalid command.");
}
Copy link

Choose a reason for hiding this comment

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

Good that the if-else statements follows the java conventions!

Comment on lines 91 to 95
Task task = new DeadlineTask(parts[0], parts[1]);
tasks.add(task);
System.out.println("Alright buddy, Added this:");
System.out.println(" " + task);
printTaskCount();

Choose a reason for hiding this comment

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

SLAP Hard
Avoid having multiple levels of abstraction within a code fragment
You can try write all things in printTaskCount() and rename this function to make more sense

Comment on lines 100 to 114
if (parts.length != 2) {
System.out.println("Invalid event format.");
return;
}
String[] timeParts = parts[1].split(" /to ");
if (timeParts.length != 2) {
System.out.println("Invalid event format.");
return;
}
Task task = new EventTask(parts[0], timeParts[0], timeParts[1]);
tasks.add(task);
System.out.println("Alright buddy, Added this:");
System.out.println(" " + task);
printTaskCount();
}

Choose a reason for hiding this comment

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

No Deep nesting, Goood

Comment on lines 36 to 50
private void processUserInput(String userInput) {
if (userInput.startsWith("todo")) {
addTodoTask(userInput.substring(5).trim());
} else if (userInput.startsWith("deadline")) {
addDeadlineTask(userInput.substring(9).trim());
} else if (userInput.startsWith("event")) {
addEventTask(userInput.substring(6).trim());
} else if (userInput.startsWith("mark")) {
markTask(userInput.substring(5).trim());
} else if (userInput.startsWith("unmark")) {
unmarkTask(userInput.substring(7).trim());
} else if (userInput.equalsIgnoreCase("list")) {
displayTaskList();
} else {
System.out.println("Invalid command.");

Choose a reason for hiding this comment

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

Good oop implementation

}

private void unmarkTask(String taskNumberStr) {
int taskNumber = Integer.parseInt(taskNumberStr) - 1;

Choose a reason for hiding this comment

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

Clear variable name

}

private void addDeadlineTask(String descriptionAndBy) {
String[] parts = descriptionAndBy.split(" /by ");

Choose a reason for hiding this comment

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

Also clear variable name

Copy link

@sevenseasofbri sevenseasofbri left a comment

Choose a reason for hiding this comment

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

Overall, code is OK. Looks like Lvl 5 has not been done yet, might want to work on that. Naming and adherance to coding standard is good. Mixed usage of abstraction, it can be more consistent. Good job 👍🏽

Comment on lines 4 to 10
/*String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
+ "|____/ \\__,_|_|\\_\\___|\n";*/

//System.out.println("Hello from\n" + logo);

Choose a reason for hiding this comment

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

Avoid leaving in commented out code. It reduces readbility.

//System.out.println("Hello from\n" + logo);
System.out.println("Hello! I'm G.one");
System.out.println("--------------------------------------");
Scanner scanner = new Scanner(System.in);

Choose a reason for hiding this comment

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

Consider naming this object a bit more intuitively? Someting along the lines of input ?

https://nus-cs2113-ay2324s2.github.io/website/se-book-adapted/chapters/codeQuality.html#use-name-to-explain

System.out.println("Hello! I'm G.one");
System.out.println("--------------------------------------");
Scanner scanner = new Scanner(System.in);
boolean flag = true;

Choose a reason for hiding this comment

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

Boolean variables should be named to sound like booleans. That is, it should be asking a question with a true/false answer.
See: https://nus-cs2113-ay2324s2.github.io/website/se-book-adapted/chapters/codeQuality.html#use-name-to-explain
Also see: https://se-education.org/guides/conventions/java/basic.html#naming

System.out.println("--------------------------------------");
Scanner scanner = new Scanner(System.in);
boolean flag = true;
while (flag){

Choose a reason for hiding this comment

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

while (flag) {
spacing between ) and { will improve readability

while (flag){
System.out.print("Whats up? ");
String userInput = scanner.nextLine();
if (userInput.equalsIgnoreCase("bye")){

Choose a reason for hiding this comment

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

Avoid magic literals in the code. Maybe consider using a static final variable instead.

https://nus-cs2113-ay2324s2.github.io/website/se-book-adapted/chapters/codeQuality.html#avoid-magic-numbers

Comment on lines 36 to 49
private void processUserInput(String userInput) {
if (userInput.startsWith("todo")) {
addTodoTask(userInput.substring(5).trim());
} else if (userInput.startsWith("deadline")) {
addDeadlineTask(userInput.substring(9).trim());
} else if (userInput.startsWith("event")) {
addEventTask(userInput.substring(6).trim());
} else if (userInput.startsWith("mark")) {
markTask(userInput.substring(5).trim());
} else if (userInput.startsWith("unmark")) {
unmarkTask(userInput.substring(7).trim());
} else if (userInput.equalsIgnoreCase("list")) {
displayTaskList();
} else {

Choose a reason for hiding this comment

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

Good use of abstraction. However, can the substring and trim portion be separated to a different function dedicated to getting a substring from the input? Mainly because this will reduce complicated expressions and improve the overall readability of this function.

}

private void addDeadlineTask(String descriptionAndBy) {
String[] parts = descriptionAndBy.split(" /by ");

Choose a reason for hiding this comment

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

parts is not a very good name. It is unclear as to what it is referring to.

https://nus-cs2113-ay2324s2.github.io/website/se-book-adapted/chapters/codeQuality.html#use-name-to-explain

printTaskCount();
}

private void addDeadlineTask(String descriptionAndBy) {

Choose a reason for hiding this comment

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

consider using a different name instead of descriptionAndBy. It reads a bit confusingly. Maybe deadlineDetails ?

Comment on lines 128 to 131
public static void main(String[] args) {
G_one g_one = new G_one();
g_one.start();
}

Choose a reason for hiding this comment

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

Again, variable names should be in camelCase and classnames in PascalCase.

Comment on lines 27 to 30




Choose a reason for hiding this comment

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

remove unnecessary space

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.

5 participants