Skip to content

Commit

Permalink
Merge pull request #131 from moseslee9012/master
Browse files Browse the repository at this point in the history
Added documentation to relevant methods for Delete function
  • Loading branch information
SongZijin committed Apr 8, 2023
2 parents 6d2df8f + 21520df commit afe5b44
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/main/java/com/clanki/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,20 @@
*/
public class DeleteCommand extends Command {

private static final String FLASHCARD_TO_DELETE = "Which one do you want to delete?";
ArrayList<Flashcard> matchingFlashcards = new ArrayList<>();
String query;

public DeleteCommand(String query) {
this.query = query;
}

/**
* Search through flashcards containing the query and adds them to the matchingFlashcards list.
*
* @param flashcards the list of flashcards to look through
* @param query the search query for finding matching flashcards
*/
public void findFlashcard(ArrayList<Flashcard> flashcards, String query) {
for (int i = 0; i < flashcards.size(); i++) {
Flashcard currentFlashcard = flashcards.get(i);
Expand All @@ -29,11 +36,21 @@ public void findFlashcard(ArrayList<Flashcard> flashcards, String query) {
}
}

/**
* Prints out the question and answer for each flashcard
*
* @param flashcard each individual flashcard in the ArrayList
*/
public void printFlashCard(Flashcard flashcard) {
System.out.println("Q: " + flashcard.getQuestion());
System.out.println("A: " + flashcard.getAnswer());
}

/**
* Goes through the ArrayList of flashcards and prints out each one of them
*
* @param flashcards the ArrayList of flashcards
*/
public void printFlashCardList(ArrayList<Flashcard> flashcards) {
for (int i = 0; i < flashcards.size(); i++) {
System.out.println("[" + (i + 1) + "]");
Expand All @@ -49,15 +66,13 @@ public void execute(FlashcardList flashcardList, Ui display) {
System.out.println(
"Found " + matchingFlashcards.size() + " cards with query \"" + query + "\":");
printFlashCardList(matchingFlashcards);
System.out.println("Which one do you want to delete?");
System.out.println(FLASHCARD_TO_DELETE);

int index = Integer.parseInt(display.getUserCommand());
flashcardList.deleteFlashcard(flashcards.indexOf(matchingFlashcards.get(index - 1)));
display.printSuccessfulDelete(index);
} else {
System.out.println("Sorry! No flashcards matching " + '\"' + query + "\" was found. Please try again.");
System.out.println("Sorry! No flashcards matching \"" + query + "\" was found. Please try again.");
}


}
}
5 changes: 5 additions & 0 deletions src/main/java/com/clanki/ui/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public void printInvalidInput() {
"You can view our user guide or type help to see the correct formats for commands.\n");
}

/**
* Prints out a message to indicate a successful deletion of a flashcard
*
* @param index the index of the flashcard at the point of deletion
*/
public void printSuccessfulDelete(int index) {
System.out.println("Got it. Deleted the flashcard at index " + index);
}
Expand Down

0 comments on commit afe5b44

Please sign in to comment.