Skip to content

Commit

Permalink
Merge 76fa4fc into cbc6ef5
Browse files Browse the repository at this point in the history
  • Loading branch information
keiteo committed Nov 10, 2019
2 parents cbc6ef5 + 76fa4fc commit 9e63fc2
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

//@@author keiteo
/**
* Ends the current flashcard test.
* Instantiates an EndTestcommand that allows users to end the current flashcard test.
*/
public class EndTestCommand extends Command {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

//@@author keiteo
/**
* Represents a NextQuestionCommand to skip questions.
* This class provides a skeletal implementation for commands that fetch the next FlashCard from the test model.
*/
abstract class NextQuestionCommand extends Command {

Expand All @@ -32,7 +32,6 @@ public CommandResult execute(Model model) {
return result;
}

//String nextQuestion = model.getTestQuestion();
model.setTestFlashCard();
keyboardFlashCardsParser.setAwaitingAnswer(true);
return new CommandResult(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,18 @@ private void updateModelStatistics(Model model) {
assert model != null;
String rating = this.rating.toString();
assert rating.equals("good") || rating.equals("hard") || rating.equals("easy");
if (rating.equals("good")) {
switch (rating) {
case "good":
model.editStats(0);
} else if (rating.equals("hard")) {
break;
case "hard":
model.editStats(1);
} else { // rating.equals("easy")
break;
case "easy":
model.editStats(2);
break;
default:
// should not reach this stage
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
public class ShowAnswerCommand extends Command {

public static final String COMMAND_WORD = "ans";
public static final String MESSAGE_SHOW_ANSWER_SUCCESS = "Answer displayed! "
+ "Please rate the FlashCard easy/good/hard.";
public static final String ERROR_MESSAGE = "Answer has already been displayed!\n"
+ "Next available command: rate, end";

Expand All @@ -26,9 +28,8 @@ public ShowAnswerCommand(KeyboardFlashCardsParser keyboardFlashCardsParser) {
public CommandResult execute(Model model) {
requireNonNull(model);
model.showAnswer();

keyboardFlashCardsParser.setAwaitingAnswer(false);
return new CommandResult("To be change: better feedback message");
return new CommandResult(MESSAGE_SHOW_ANSWER_SUCCESS);
}

@Override
Expand Down
15 changes: 7 additions & 8 deletions src/main/java/seedu/address/logic/commands/StartCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,22 @@

//@@author keiteo
/**
* Starts the flashcard test by going through the cards in the specified deck.
* If no deck name is supplied, a random deck will be chosen.
* Instantiates a StartCommand to allow users to start the flashcard test
* by going through the cards in the specified tag(s).
* If no tags are supplied, all FlashCards will be used.
*/
public class StartCommand extends Command {

public static final String COMMAND_WORD = "start";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Starts the FlashCard test by going through the cards in the specified deck.\n"
+ "Parameters: DECK NAME. If no argument is supplied, a random deck will be chosen.\n"
+ "Parameters: tag(s). If no argument is supplied, all FlashCards will be used.\n"
+ "Example: " + COMMAND_WORD + " physics";

public static final String MESSAGE_NO_FLASHCARDS = "No FlashCard to test!";
public static final String MESSAGE_NO_FLASHCARDS = "No FlashCards to test!";

public static final String MESSAGE_START_TEST_SUCCESS = "Starting test...\n";
public static final String MESSAGE_START_TEST_SUCCESS = "Starting test...";

private final KeyboardFlashCardsParser keyboardFlashCardsParser;

Expand All @@ -49,7 +50,6 @@ public CommandResult execute(Model model) {
}
keyboardFlashCardsParser.startTestMode();
model.setTestFlashCard();
//String question = model.getTestQuestion();
keyboardFlashCardsParser.setAwaitingAnswer(true);

CommandResult result = new CommandResult(
Expand All @@ -75,8 +75,7 @@ private List<FlashCard> searchTag(Model model) {
return new LinkedList<>(model.getFlashCardList());
}
CategoryContainsAnyKeywordsPredicate predicate = getSearchTermPredicate();
model.updateFilteredFlashCardList(predicate);
return new LinkedList<>(model.getFilteredFlashCardList());
return new LinkedList<>(model.getFilteredFlashCardListNoCommit(predicate));
}

/** Converts tagName to a CategoryContainsAnyKeywordsPredicate for searchTag(). */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,25 @@ public Command parseCommand(String userInput) throws ParseException {
}

//@@author keiteo

/**
* Sets test mode to be true to disable parsing of non-test commands.
*/
public void startTestMode() {
isRunningFlashcardTest = true;
}

/**
* Sets test mode to be false to enable parsing of non-test commands.
*/
public void endTestMode() {
isRunningFlashcardTest = false;
}

/**
* Sets the answer status in test mode to further restrict inappropriate test commands.
* @param isAwaitingAnswer True if the program is waiting for user input to show answer, otherwise false.
*/
public void setAwaitingAnswer(boolean isAwaitingAnswer) {
this.isAwaitingAnswer = isAwaitingAnswer;
}
Expand Down Expand Up @@ -110,7 +121,7 @@ private Command parseTestCommand(Matcher matcher) throws ParseException {
}
}

//@@author
//@@author keiteo-reused
/** Parses commands outside test mode i.e. list, add etc. */
private Command parseNormalCommand(Matcher matcher) throws ParseException {
final String commandWord = matcher.group("commandWord");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

//@@author keiteo
/**
* Parses input arguments and creates a new RateQuestionCommand object.
* This class parses input arguments and creates a new RateQuestionCommand object.
*/
public class RateQuestionCommandParser implements Parser<RateQuestionCommand> {

Expand All @@ -26,7 +26,6 @@ public RateQuestionCommandParser(KeyboardFlashCardsParser keyboardFlashCardsPars
*/
public RateQuestionCommand parse(String args) throws ParseException {
String getFirstWord = args.trim().split("\\s+")[0];

switch (getFirstWord) {
case Rating.EASY:
case Rating.GOOD:
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/seedu/address/logic/parser/StartCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
import static java.util.Objects.requireNonNull;

import seedu.address.logic.commands.StartCommand;
import seedu.address.logic.parser.exceptions.ParseException;

//@@author keiteo
/**
* Parses input arguments and creates a new StartCommand object.
* This class parses input arguments and creates a new StartCommand object.
*/
public class StartCommandParser implements Parser<StartCommand> {

public static final String BAD_ARGUMENTS = "Please make sure your tags are alphanumeric!";

private final KeyboardFlashCardsParser keyboardFlashCardsParser;

StartCommandParser(KeyboardFlashCardsParser keyboardFlashCardsParser) {
Expand All @@ -20,7 +23,11 @@ public class StartCommandParser implements Parser<StartCommand> {
* Parses the given {@code String} of arguments in the context of the StartCommand
* and returns a StartCommand object for execution.
*/
public StartCommand parse(String args) {
public StartCommand parse(String args) throws ParseException {
String alphaNumericWithSpacesRegex = "^[a-zA-Z0-9\\s+]+$";
if (!args.matches(alphaNumericWithSpacesRegex) && !args.isEmpty()) {
throw new ParseException(BAD_ARGUMENTS);
}
String trimmedArgs = args.trim();
return new StartCommand(keyboardFlashCardsParser, trimmedArgs);
}
Expand Down
25 changes: 19 additions & 6 deletions src/main/java/seedu/address/model/FlashCardTestModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,39 @@

import static java.util.Objects.requireNonNull;

import java.util.LinkedList;
import java.util.List;

import seedu.address.model.flashcard.FlashCard;
import seedu.address.ui.TestFlashCardPanel;

//@@author keiteo
/**
* Creates a test model to contain relevant flashcards to test users.
* Instantiates a test model to contain relevant flashcards to test users.
*/
public class FlashCardTestModel {

private static FlashCard currentFlashCard;
private FlashCard currentFlashCard;

private List<FlashCard> testList;
private List<FlashCard> testListOld = new LinkedList<>(); // placeholder for previous function
private TestFlashCardPanel testFlashCardPanel;

public FlashCardTestModel(List<FlashCard> testList) {
this.testList = testList;
}

/**
* Checks if the test list is empty.
*/
public boolean isEmpty() {
return testList.isEmpty();
}

/**
* Removes a FlashCard from the head of the test list and sets it as the current FlashCard.
*/
public void setFlashcard() {
assert !testList.isEmpty();
currentFlashCard = testList.remove(0);
testListOld.add(currentFlashCard);
}

//@@author shutingy
Expand All @@ -55,17 +58,27 @@ public void showAnswer() {
}

//@@author keiteo

/**
* Gets the question of the current FlashCard.
*/
public String getQuestion() {
requireNonNull(currentFlashCard);
return currentFlashCard.getQuestion().toString();
}

/**
* Gets the answer of the current FlashCard.
*/
public String getAnswer() {
requireNonNull(currentFlashCard);
return currentFlashCard.getAnswer().toString();
}

public static FlashCard getCurrentFlashCard() {
/**
* Gets the current FlashCard.
*/
FlashCard getCurrentFlashCard() {
return currentFlashCard;
}

Expand Down
29 changes: 29 additions & 0 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,19 +155,48 @@ public interface Model {
void updateFilteredCategoryList(Predicate<Category> predicate);

//@@author keiteo

/**
* Returns an entire list of FlashCards in the system.
* @return An ObservableList of FlashCards
*/
ObservableList<FlashCard> getFlashCardList();

/**
* Initializes the test mode model with a list of FlashCards.
* @param testList List of FlashCards to be tested.
*/
void initializeTestModel(List<FlashCard> testList);

/**
* Checks if the list of FlashCards in the test model is fully expended.
* @return A boolean to indicate if the test model still has FlashCards.
*/
boolean hasTestFlashCard();

/**
* Sets the current FlashCard in the TestFlashCardPanel GUI.
*/
void setTestFlashCard();

/**
* Gets the test FlashCard question.
*/
String getTestQuestion();

/**
* Gets the test FlashCard answer.
*/
String getTestAnswer();

/**
* Gets the TestFlashCardPanel GUI class.
*/
TestFlashCardPanel getTestFlashCardPanel();

/**
* Gets the current FlashCard in test mode.
*/
FlashCard getCurrentTestFlashCard();

//@@author shutingy
Expand Down

0 comments on commit 9e63fc2

Please sign in to comment.