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

[Liu Hao] ip #115

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

[Liu Hao] ip #115

wants to merge 36 commits into from

Conversation

AaronZZ10
Copy link

No description provided.

String input = sc.nextLine();
List<Task> tasks = new ArrayList<>();
while(!input.equals("bye")) {
if(input.equals("list")) {
Copy link

Choose a reason for hiding this comment

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

Is it possible to use a switch-case instead of if-else?

if(input.equals("list")) {
System.out.println(line);
System.out.println("Here are the tasks in your list:");
for(int i = 0; i < tasks.size(); i++) {
Copy link

Choose a reason for hiding this comment

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

Since tasks.size() is repeated used in all of the loops, perhaps can create a variable to store this value

if(input.startsWith("mark")){
String[] words = input.split(" ");
int index = Integer.parseInt(words[1])-1;
if(index<0 || index>=tasks.size()) {
Copy link

Choose a reason for hiding this comment

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

Perhaps can place the code for checking in a method to allow easier reading


String input = sc.nextLine();
List<Task> tasks = new ArrayList<>();
while(!input.equals("bye")) {
Copy link

Choose a reason for hiding this comment

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

For all the printing of the statements, maybe can put it in a method each. For instance, printTodoAdded() and the statement that the todo task have been added will be printed

int from = input.indexOf("/from");
int to = input.indexOf("/to");
String description = input.substring(6,from);
String _from = input.substring(from+6,to);
Copy link

Choose a reason for hiding this comment

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

Preferably used another name instead of _from or _to as it is similar as from and to, which can be confusing

Copy link

@PrinceCatt PrinceCatt left a comment

Choose a reason for hiding this comment

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

  1. Your base class of tasks and other classes extending it look quite nice
  2. Coding standard looks good to me
  3. Your naming is not very consistent. Some are camelCasem while some are not: like _by
  4. Plural fine, boolean naming fine,

Copy link

@kaboomzxc kaboomzxc left a comment

Choose a reason for hiding this comment

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

good code quality

import java.util.*;

// Main class to implement a task manager called "Taylor"
public class Taylor {

Choose a reason for hiding this comment

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

didn't do deep nesting, which is good code quality

// Initialize a scanner object to take user input
Scanner sc = new Scanner(System.in);

// Define a separator line for display purposes

Choose a reason for hiding this comment

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

appropriate code comments explanations are helpful

if(input.startsWith("mark")){
String[] words = input.split(" ");
int index = Integer.parseInt(words[1])-1; // Parse task index
if(index<0 || index>=tasks.size()) { // Check if index is valid

Choose a reason for hiding this comment

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

error handling for Invalid Input is very useful

}

// Handle "todo" command to add a new Todo task
if(input.startsWith("todo")){

Choose a reason for hiding this comment

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

Clear input handling for all the multiple types of commands (list, mark, unmark, todo, event, deadline)

Copy link

@tzerbin tzerbin left a comment

Choose a reason for hiding this comment

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

Good attempt in following the guidelines!

Just a few things with regards to switch statements, magic numbers/strings and descriptive names for methods.

* @throws IOException If an I/O error occurs while reading the file.
* @throws TaylorException If the file contains an unknown task type.
*/
public ArrayList<Task> load() throws IOException, TaylorException {
Copy link

Choose a reason for hiding this comment

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

Perhaps provide a better descriptive name for the method?
This applies to the method names in this file such as "save" as well.

String description = parts[2].trim();

switch (taskType) {
case "T" -> tasks.add(new Todo(description, isCompleted));
Copy link

Choose a reason for hiding this comment

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

Please follow the structure of switch statements using breaks and colons, instead of arrow.

* The Taylor class handles user commands and manages task operations.
*/
public class Taylor {
private final Storage storage;
Copy link

Choose a reason for hiding this comment

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

Constants should use SCREAMING_SNAKE_CASE instead.

* @return The next user command input.
* @throws TaylorException If an unknown command is encountered.
*/
private String operate(String input) throws TaylorException {
Copy link

Choose a reason for hiding this comment

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

This method is very long, perhaps abstract some details out into new functions (especially for the code in switch statements)?

ui.showTaskAdded(tasks.get(index), tasks);
storage.save(tasks);
} catch (IOException e) {
ui.println("Unable to write to file");
Copy link

Choose a reason for hiding this comment

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

There are a lot of instances of magic numbers and strings in the codebase, please use constants instead.

/**
* Displays the welcome message when the program starts.
*/
public void showWelcome() {
Copy link

Choose a reason for hiding this comment

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

It would be more appropriate to use the verb "print" instead of "show".
This applies to other methods in this file.


import java.util.Scanner;

/**
Copy link

Choose a reason for hiding this comment

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

Very nice usage of comments in all files.

*
* @return A string representing the task suitable for file storage.
*/
public abstract String write();
Copy link

Choose a reason for hiding this comment

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

Please use more descriptive method name!

Suggested change
public abstract String write();
public abstract String writeToFile();

* @param keyword The keyword to search for in the task descriptions.
* @return A string containing the matching tasks with their index, or null if no match is found.
*/
public String find(String keyword) {
Copy link

Choose a reason for hiding this comment

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

This method could use a more descriptive name as well.

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