Skip to content

Commit

Permalink
Merge 04ae604 into 03366b7
Browse files Browse the repository at this point in the history
  • Loading branch information
keiteo committed Nov 3, 2019
2 parents 03366b7 + 04ae604 commit 2eba1f7
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/commons/core/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
public class Messages {

public static final String MESSAGE_UNKNOWN_COMMAND = "Unknown command";
public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s";
public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format!\n%1$s";
public static final String MESSAGE_INVALID_FLASHCARD_DISPLAYED_INDEX = "The flashcard index provided is invalid";
public static final String MESSAGE_INVALID_DEADLINE_DISPLAYED_INDEX = "The deadline index provided is invalid";
public static final String MESSAGE_INVALID_THEME =
"The theme is not available. Existing themes: dark, light, pink, blue, hacker, nus";
public static final String MESSAGE_FLASHCARD_LISTED_OVERVIEW = "%1$d flash cards listed!";
public static final String MESSAGE_UNKNOWN_TEST_COMMAND = "Unknown test command";
public static final String MESSAGE_UNKNOWN_TEST_COMMAND = "Unknown test command!\n%1$s";
public static final String MESSAGE_EXPORT_IO_EXCEPTION = "There was an error in writing to the file.\n"
+ "Please ensure your file path doesn't contain any illegal characters.";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;

import seedu.address.logic.parser.KeyboardFlashCardsParser;
import seedu.address.model.Model;

/**
* Instantiates a NextQuestionCommand to skip questions.
*/
public class NextQuestionCommand extends Command {

public static final String MESSAGE_SUCCESS_END_OF_TEST = "End of test!";

private final KeyboardFlashCardsParser keyboardFlashCardsParser;
private final String messageSuccess;

public NextQuestionCommand(KeyboardFlashCardsParser keyboardFlashCardsParser, String messageSuccess) {
this.keyboardFlashCardsParser = keyboardFlashCardsParser;
this.messageSuccess = messageSuccess;
}

@Override
public CommandResult execute(Model model) {
requireNonNull(model);
if (!model.hasTestFlashCard()) {
keyboardFlashCardsParser.endTestMode();
model.endFlashCardTest();
return new CommandResult(MESSAGE_SUCCESS_END_OF_TEST);
}

String nextQuestion = model.getTestQuestion();
keyboardFlashCardsParser.setAwaitingAnswer(true);
return new CommandResult(String.format(messageSuccess, nextQuestion));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,20 @@
/**
* Allows users to rate the flashcard question and processes the next question.
*/
public class RateQuestionCommand extends Command {
public class RateQuestionCommand extends NextQuestionCommand {

public static final String COMMAND_WORD = "rate";
public static final String MESSAGE_SUCCESS = "Rated successfully! Here's the next question:\n%s";
public static final String MESSAGE_SUCCESS_END_OF_TEST = "End of test!";
public static final String ERROR_MESSAGE = "You can only rate after answering the question!\n"
+ "Next available command: ans, skip, end";
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Rates a flashcard and gets the next question.\n"
+ "Parameter: rate easy/good/hard";

private final KeyboardFlashCardsParser keyboardFlashCardsParser;
private final Rating rating;

public RateQuestionCommand(KeyboardFlashCardsParser keyboardFlashCardsParser, Rating rating) {
requireNonNull(keyboardFlashCardsParser);
super(keyboardFlashCardsParser, MESSAGE_SUCCESS);
requireNonNull(rating);
this.keyboardFlashCardsParser = keyboardFlashCardsParser;
this.rating = rating;
Expand All @@ -34,15 +35,7 @@ public CommandResult execute(Model model) {
requireNonNull(model);
updateModelStatistics(model);
updateFlashCardRating(model);

if (!model.hasTestFlashCard()) {
keyboardFlashCardsParser.endTestMode();
return new CommandResult(MESSAGE_SUCCESS_END_OF_TEST);
}

String nextQuestion = model.getTestQuestion();
keyboardFlashCardsParser.setAwaitingAnswer(true);
return new CommandResult(String.format(MESSAGE_SUCCESS, nextQuestion));
return super.execute(model);
}

@Override
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 ERROR_MESSAGE = "Answer has already been displayed!\n"
+ "Next available command: rate, end";

private final KeyboardFlashCardsParser keyboardFlashCardsParser;

Expand Down
25 changes: 25 additions & 0 deletions src/main/java/seedu/address/logic/commands/SkipCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package seedu.address.logic.commands;

import seedu.address.logic.parser.KeyboardFlashCardsParser;
import seedu.address.model.Model;

/**
* This creates a SkipCommand object that allows users to skip the current question.
*/
public class SkipCommand extends NextQuestionCommand {

public static final String COMMAND_WORD = "skip";
public static final String MESSAGE_SUCCESS = "Successfully skipped question! Here's the next question:\n%s";
public static final String ERROR_MESSAGE = "You can only skip after seeing the question!\n"
+ "Next available command: rate, end";
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Skips a flashcard and gets the next question.";

public SkipCommand(KeyboardFlashCardsParser keyboardFlashCardsParser) {
super(keyboardFlashCardsParser, MESSAGE_SUCCESS);
}

@Override
public CommandResult execute(Model model) {
return super.execute(model);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import seedu.address.logic.commands.SearchQuestionCommand;
import seedu.address.logic.commands.SetThemeCommand;
import seedu.address.logic.commands.ShowAnswerCommand;
import seedu.address.logic.commands.SkipCommand;
import seedu.address.logic.commands.StartCommand;
import seedu.address.logic.commands.StatsCommand;

Expand Down Expand Up @@ -85,14 +86,27 @@ public void setAwaitingAnswer(boolean isAwaitingAnswer) {
private Command parseTestCommand(Matcher matcher) throws ParseException {
final String commandWord = matcher.group("commandWord");
final String arguments = matcher.group("arguments");
if (commandWord.equals(EndTestCommand.COMMAND_WORD)) {
switch (commandWord) {
case EndTestCommand.COMMAND_WORD:
return new EndTestCommand(this);
} else if (commandWord.equals(ShowAnswerCommand.COMMAND_WORD) && isAwaitingAnswer) {
return new ShowAnswerCommand(this);
} else if (commandWord.equals(RateQuestionCommand.COMMAND_WORD) && !isAwaitingAnswer) {
return new RateQuestionCommandParser(this).parse(arguments);
case ShowAnswerCommand.COMMAND_WORD:
if (isAwaitingAnswer) {
return new ShowAnswerCommand(this);
}
throw new ParseException(String.format(MESSAGE_UNKNOWN_TEST_COMMAND, ShowAnswerCommand.ERROR_MESSAGE));
case RateQuestionCommand.COMMAND_WORD:
if (!isAwaitingAnswer) {
return new RateQuestionCommandParser(this).parse(arguments);
}
throw new ParseException(String.format(MESSAGE_UNKNOWN_TEST_COMMAND, RateQuestionCommand.ERROR_MESSAGE));
case SkipCommand.COMMAND_WORD:
if (isAwaitingAnswer) {
return new SkipCommand(this);
}
throw new ParseException(String.format(MESSAGE_UNKNOWN_TEST_COMMAND, SkipCommand.ERROR_MESSAGE));
default:
throw new ParseException(String.format(MESSAGE_UNKNOWN_TEST_COMMAND, ""));
}
throw new ParseException(MESSAGE_UNKNOWN_TEST_COMMAND);
}

//@@author
Expand Down
1 change: 0 additions & 1 deletion src/main/java/seedu/address/model/FlashCardTestModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public boolean isEmpty() {
}

public String getQuestion() {

assert !testList.isEmpty();
currentFlashCard = testList.remove(0);
return currentFlashCard.getQuestion().toString();
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ public interface Model {

FlashCard getCurrentTestFlashCard();

void endFlashCardTest();

/**
* Replaces the given flashCard {@code target} with {@code editedFlashCard}.
* {@code target} must exist in the address book.
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@ public String getTestAnswer() {

}

@Override
public void endFlashCardTest() {
showFlashCardList();
}

@Override
public FlashCard getCurrentTestFlashCard() {
return flashCardTestModel.getCurrentFlashCard();
Expand All @@ -246,6 +251,11 @@ private void hideFlashCardList() {
updateFilteredFlashCardList(pred -> false);
}

/** Shows the entire list of flashcards. */
private void showFlashCardList() {
updateFilteredFlashCardList(pred -> true);
}

//@@author LeowWB
@Override
public ObservableList<FlashCard> getFilteredFlashCardListNoCommit(Predicate<FlashCard> predicate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,12 @@ public FlashCard getCurrentTestFlashCard() {
throw new AssertionError("This method should not be called.");
}

@Override
public void endFlashCardTest() {
throw new AssertionError("This method should not be called.");
}


//@@author LeowWB
public ObservableList<FlashCard> getFilteredFlashCardListNoCommit(Predicate<FlashCard> predicate) {
throw new AssertionError("This method should not be called.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ public void parseCommand_startNoParameter_success() throws Exception {
@Test
public void parseCommand_startAlreadyInTestMode_throwsParseException() {
parser.startTestMode();
assertThrows(ParseException.class, MESSAGE_UNKNOWN_TEST_COMMAND, () -> parser.parseCommand("start"));
assertThrows(ParseException.class,
String.format(MESSAGE_UNKNOWN_TEST_COMMAND, ""), () -> parser.parseCommand("start"));
}

@Test
Expand Down

0 comments on commit 2eba1f7

Please sign in to comment.