[Rawal Aarav] iP#172
Conversation
| import java.util.List; | ||
| import java.util.Scanner; | ||
|
|
||
| public class G_one { |
There was a problem hiding this comment.
the public class G_one should be named using PacalCase ( gOne/GOne)
| @@ -0,0 +1,132 @@ | |||
| import java.util.ArrayList; | |||
There was a problem hiding this comment.
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."); |
| G_one g_one = new G_one(); | ||
| g_one.start(); | ||
| } | ||
| } |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Should this Boolean variable be named to sound like booleans? eg. isRunning etc
| } | ||
|
|
||
| System.out.println("Goodbye!"); | ||
| scanner.close(); |
There was a problem hiding this comment.
Very nice detail to close scanner in order to indicate that you're done with its underlying stream!
| 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); | ||
| } | ||
| } |
| @@ -0,0 +1,13 @@ | |||
| public class DeadlineTask extends Task { | |||
There was a problem hiding this comment.
Great that DeadlineTask Class name is a noun and written in PascalCase!
| } | ||
|
|
||
| private void addEventTask(String descriptionAndTime) { | ||
| String[] parts = descriptionAndTime.split(" /from "); |
There was a problem hiding this comment.
Good that array specifiers are attached to the type not the variable!
| 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."); | ||
| } |
There was a problem hiding this comment.
Good that the if-else statements follows the java conventions!
| Task task = new DeadlineTask(parts[0], parts[1]); | ||
| tasks.add(task); | ||
| System.out.println("Alright buddy, Added this:"); | ||
| System.out.println(" " + task); | ||
| printTaskCount(); |
There was a problem hiding this comment.
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
| 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(); | ||
| } |
| 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."); |
| } | ||
|
|
||
| private void unmarkTask(String taskNumberStr) { | ||
| int taskNumber = Integer.parseInt(taskNumberStr) - 1; |
| } | ||
|
|
||
| private void addDeadlineTask(String descriptionAndBy) { | ||
| String[] parts = descriptionAndBy.split(" /by "); |
sevenseasofbri
left a comment
There was a problem hiding this comment.
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 👍🏽
| /*String logo = " ____ _ \n" | ||
| + "| _ \\ _ _| | _____ \n" | ||
| + "| | | | | | | |/ / _ \\\n" | ||
| + "| |_| | |_| | < __/\n" | ||
| + "|____/ \\__,_|_|\\_\\___|\n"; | ||
| System.out.println("Hello from\n" + logo); | ||
| + "|____/ \\__,_|_|\\_\\___|\n";*/ | ||
|
|
||
| //System.out.println("Hello from\n" + logo); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Consider naming this object a bit more intuitively? Someting along the lines of input ?
| System.out.println("Hello! I'm G.one"); | ||
| System.out.println("--------------------------------------"); | ||
| Scanner scanner = new Scanner(System.in); | ||
| boolean flag = true; |
There was a problem hiding this comment.
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){ |
There was a problem hiding this comment.
while (flag) {
spacing between ) and { will improve readability
| while (flag){ | ||
| System.out.print("Whats up? "); | ||
| String userInput = scanner.nextLine(); | ||
| if (userInput.equalsIgnoreCase("bye")){ |
There was a problem hiding this comment.
Avoid magic literals in the code. Maybe consider using a static final variable instead.
| 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 { |
There was a problem hiding this comment.
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 "); |
There was a problem hiding this comment.
parts is not a very good name. It is unclear as to what it is referring to.
| printTaskCount(); | ||
| } | ||
|
|
||
| private void addDeadlineTask(String descriptionAndBy) { |
There was a problem hiding this comment.
consider using a different name instead of descriptionAndBy. It reads a bit confusingly. Maybe deadlineDetails ?
| public static void main(String[] args) { | ||
| G_one g_one = new G_one(); | ||
| g_one.start(); | ||
| } |
There was a problem hiding this comment.
Again, variable names should be in camelCase and classnames in PascalCase.
|
|
||
|
|
||
|
|
||
|
|
This reverts commit 7b5aff0.
No description provided.