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

[AB3: Tracing Code] Enhance conclusion to provide answers for students #25

Open
ruth-lim opened this issue Jun 25, 2024 · 5 comments
Open

Comments

@ruth-lim
Copy link

Current

Picture 2

Problem

This section is relevant and can be helpful for students to check on their understanding. However, as no answers are provided it falls short of allowing students to check their knowledge fully as they cannot verify whether their answers and path tracing are correct.

Proposed

Have a drop-down to reveal the answers for students to reference to, similar to the CS2103T website:
Picture 3

@damithc
Copy link
Contributor

damithc commented Jul 3, 2024

@ruth-lim Yes, this could be useful. If you can post the answers here, I can add them to the tutorial.

@ruth-lim
Copy link
Author

Answers for Question 1

1. redit 1 n/Alice Yu

  • Exception Thrown: ParseException
  • Reason: Unknown command as the command word redit is not recognized.
  • Where the exception is thrown: AddressBookParser#parseCommand()
java {.line-numbers highlight-lines="7"}
public Command parseCommand(String userInput) throws ParseException {
    ...
    switch (commandWord) {
    ...
    default:
        logger.finer("This user input caused a ParseException: " + userInput);
        throw new ParseException(MESSAGE_UNKNOWN_COMMAND);
    }
}
  • Where the exception is handled: MainWindow#executeCommand()
java {.line-numbers highlight-lines="3"}
private CommandResult executeCommand(String commandText) throws CommandException, ParseException {
    ...
    } catch (CommandException | ParseException e) {
        logger.info("An error occurred while executing command: " + commandText);
        resultDisplay.setFeedbackToUser(e.getMessage());
        throw e;
    }
}

2. edit 0 n/Alice Yu

  • Exception Thrown: ParseException
  • Reason: Invalid command format as index 0 is not a non-zero unsigned integer.
  • Where the exception is thrown: EditCommandParser#parse()
java {.line-numbers highlight-lines="6"}
public EditCommand parse(String args) throws ParseException {
  ...
  try {
      index = ParserUtil.parseIndex(argMultimap.getPreamble());
  } catch (ParseException pe) {
      throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE), pe);
  }
  ...
}
  • Where the exception is handled: MainWindow#executeCommand()

3. edit 1 n/Alex Yeoh

  • No exception thrown.
  • Reason: "1" is a valid index in the person list. The command is correctly formatted and will edit the name of the person at index 1 to "Alex Yeoh".

4. edit 1

  • Exception Thrown: ParseException
  • Reason: At least one field to edit must be provided.
  • Where the exception is thrown: EditCommandParser#parse()
java {.line-numbers highlight-lines="4"}
public EditCommand parse(String args) throws ParseException {
  ...
  if (!editPersonDescriptor.isAnyFieldEdited()) {
      throw new ParseException(EditCommand.MESSAGE_NOT_EDITED);
  }
  ...
}
  • Where the exception is handled: MainWindow#executeCommand()

5. edit 1 n/アリス ユー

  • Exception Thrown: ParseException
  • Reason: Names should only contain alphanumeric characters and spaces, and it should not be blank.
  • Where the exception is thrown: ParserUtil#parseName()
java {.line-numbers highlight-lines="4"}
public static Name parseName(String name) throws ParseException {
  ...
  if (!Name.isValidName(trimmedName)) {
      throw new ParseException(Name.MESSAGE_CONSTRAINTS);
  }
  ...
}
  • Where the exception is handled: MainWindow#executeCommand()

6. edit 1 t/one t/two t/three t/one

  • No exception thrown.
  • Reason: The command is correctly formatted and will edit the tags of the person at index 1 to "one", "two" and "three".
<panel header="Why didn’t the second tag with value “one” get added?">
   <p>Duplicate values are handled by the `ParserUtil#parseTags()` method because tags are added to a HashSet. The HashSet class inherently handles duplicates by not allowing any equal elements to be added. Therefore, any duplicate tags are not added.
     <br> Read more on the `add` method of the HashSet class <a href="https://docs.oracle.com/javase/8/docs/api/java/util/HashSet.html#add-E-">here</a>.
   </p>
</panel>

@ruth-lim
Copy link
Author

Answers for Question 2

1. Make command words case-insensitive

  1. Modify AddressBookParser#parseCommand() to convert command words to lowercase before parsing.

        ```java {.line-numbers highlight-lines="3['.toLowerCase()']"}
        public Command parseCommand(String userInput) throws ParseException {
            ...
            final String commandWord = matcher.group("commandWord").toLowerCase();
            final String arguments = matcher.group("arguments");
        }
        ```
    

2. Allow delete to remove more than one index at a time

  1. Modify DeleteCommandParser to parse a list of indices.
  2. Update DeleteCommand to take in a list of indices.
<box type="info" seamless>

              Remember to update other usages of `DeleteCommand` class to handle the change in type of Index.
</box>

3. Save the address book in the CSV format instead

  1. Import the following classes:

           ```java
           import java.io.FileWriter;
           import java.io.PrintWriter;
           ```
    
  2. Modify the JsonAddressBookStorage#saveAddressBook() method.

           ```java
           public void saveAddressBook(ReadOnlyAddressBook addressBook, Path filePath) throws IOException {
            requireNonNull(addressBook);
            requireNonNull(filePath);
    
            FileUtil.createIfMissing(filePath);
    
            try (PrintWriter out = new PrintWriter(new FileWriter(filePath.toFile()))) {
                out.println("Name,Phone,Email,Address,Tags"); // CSV header
                addressBook.getPersonList().forEach(person -> {
                    out.println(
                            escapeField(person.getName().toString()) + "," +
                            escapeField(person.getPhone().toString()) + "," +
                            escapeField(person.getEmail().toString()) + "," +
                            escapeField(person.getAddress().toString()) + "," +
                            escapeField(person.getTags().toString())
                    );
                });
            } catch (IOException e) {
                logger.severe("Failed to save address book to " + filePath + ": " + e.getMessage());
                throw e;
            }
           }
           ```
    
  3. Add a helper method to handle special characters in the fields for Person.

           ```java
           private String escapeField(String field) {
               if (field.contains(",") || field.contains("\"")) {
               field = field.replace("\"", "\"\"");
               field = "\"" + field + "\"";
           }
           return field;
           }
           ```
    

4. Add a new command

  1. Add a class for your new command in the seedu.address.logic.commands package.
  2. Add a class for your parser to parse the new command in the seedu.address.logic.parser package.
  3. Update AddressBookParser to use the new parser.
<box type="info" seamless>
      For a more detailed explanation, refer to <a href="https://se-education.org/guides/tutorials/ab3AddRemark.html">[AB3 Tutorial: Adding a Command]</a>
</box>

5. Add a new field to Person

  1. Add a new class for the field in seedu.address.model.person.
  2. Update the Person class to include the new field.
  3. Update the JsonAdaptedPerson class in seedu.address.storage to include the new field.
<box type="info" seamless>
           
     Remember to update other usages of `Person` class to handle the new field.
</box>

6. Add a new entity to the address book

For instance, if we are adding Event as the new entity to the address book:

  1. Add a new class Event in seedu.address.model.event to represent an Event entity.
  2. Add a new class AddEventCommand in seedu.address.logic.commands that is similar to AddCommand.
  3. Implement a AddEventCommandParser parser in seedu.address.logic.parser to parse the relevant arguments.
  4. Update the Model interface to add in new methods such as addEvent and hasEvent.
  5. Update the ModelManager to implement these new methods.
  6. Update the AddressBook class to create methods like setEvent or getEventList etc.
  7. Create a UniqueEventList class in seedu.address.model.event to handle a list of unique events.
  8. Implement a JsonAdaptedEvent in seedu.address.storage to save the data in JSON format.

@damithc
Copy link
Contributor

damithc commented Jul 21, 2024

@se-edu/summer-2024-pr-reviewers This is not a PR yet, but your inputs on the proposed content welcome.

@damithc
Copy link
Contributor

damithc commented Aug 11, 2024

@ruth-lim Feel free to create a PR for this.

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 a pull request may close this issue.

2 participants