diff --git a/src/main/java/seedu/address/flashcard/CardId.java b/src/main/java/seedu/address/flashcard/CardId.java new file mode 100644 index 00000000000..d0d49863ed3 --- /dev/null +++ b/src/main/java/seedu/address/flashcard/CardId.java @@ -0,0 +1,55 @@ +package seedu.address.flashcard; + +/** + * The unique identity number for each flash card. + * Guarantees: Each card's id number is unique. + */ +public class CardId { + + // The id number for the next flash card generated. + private static int frontier = 0; + private final int identityNumber; + + /** + * Constructor of the class, automatically generate a unique identity number. + */ + public CardId() { + identityNumber = frontier; + frontier++; + } + + public int getIdentityNumber() { + return identityNumber; + } + + /** + * While finding a flashcard, compare that the id number of this card matches the search string or not. + * @param s The search parameter, target string. + * @return true if the id number indeed contains the target information, false otherwise. + */ + public boolean contains(String s) { + String idAsString = Integer.toString(identityNumber); + return idAsString.contains(s); + } + + @Override + public String toString() { + return Integer.toString(identityNumber); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof CardId)) { + return false; + } + return identityNumber == ((CardId) other).getIdentityNumber(); + } + + @Override + public int hashCode() { + return identityNumber; + } +} diff --git a/src/main/java/seedu/address/flashcard/Score.java b/src/main/java/seedu/address/flashcard/Score.java new file mode 100644 index 00000000000..4f0bdc33530 --- /dev/null +++ b/src/main/java/seedu/address/flashcard/Score.java @@ -0,0 +1,52 @@ +package seedu.address.flashcard; + +/** + * The record of how many correct and wrong answers has the user done. + */ +public class Score { + + private static final String MESSAGE_BEFORE_TOTAL = "Total number of practices: "; + private static final String MESSAGE_BEFORE_CORRECT = "Number of correct answers: "; + private static final String MESSAGE_BEFORE_WRONG = "Number of wrong answer: "; + private static final String MESSAGE_BEFORE_PERCENTAGE = "Total Correct rate: "; + private int correctAnswerNumber; + private int wrongAnswerNumber; + + public Score() { + correctAnswerNumber = 0; + wrongAnswerNumber = 0; + } + + public int getCorrectAnswerNumber() { + return correctAnswerNumber; + } + + public int getWrongAnswerNumber() { + return wrongAnswerNumber; + } + + public void addCorrectAnswerNumber() { + correctAnswerNumber++; + } + + public void addWrongAnswerNumber() { + wrongAnswerNumber++; + } + + public int getTotalAnswerNumber() { + return correctAnswerNumber + wrongAnswerNumber; + } + + public float getCorrectRate() { + return correctAnswerNumber / getCorrectAnswerNumber(); + } + + @Override + public String toString() { + String totalMessage = MESSAGE_BEFORE_TOTAL + Integer.toString(getTotalAnswerNumber()) + "\n"; + String correctMessage = MESSAGE_BEFORE_CORRECT + Integer.toString(getCorrectAnswerNumber()) + "\n"; + String wrongMessage = MESSAGE_BEFORE_WRONG + Integer.toString(getWrongAnswerNumber()) + "\n"; + String percentageMessage = MESSAGE_BEFORE_PERCENTAGE + Float.toString(getCorrectRate()) + "\n"; + return totalMessage + correctMessage + wrongMessage + percentageMessage; + } +} diff --git a/src/main/java/seedu/address/flashcard/TimeLimit.java b/src/main/java/seedu/address/flashcard/TimeLimit.java new file mode 100644 index 00000000000..760f94aae69 --- /dev/null +++ b/src/main/java/seedu/address/flashcard/TimeLimit.java @@ -0,0 +1,60 @@ +package seedu.address.flashcard; + +import static seedu.address.commons.util.AppUtil.checkArgument; + +/** + * The time limit for doing a quiz + * Guarantees: Does not exceed an hour, minutes and seconds are both between 0 and 60. + */ +public class TimeLimit { + + private static final String MESSAGE_CONSTRAINTS = "Time limit must be in the format of two integers," + + "representing minutes and seconds respectively. Since this a flashcard system, we do not " + + "support time limit more than or equals to an hour."; + private static final String MESSAGE_AFTER_MINUTES = " minutes "; + private static final String MESSAGE_AFTER_SECONDS = " seconds "; + private int minutes; + private int seconds; + + // Default Time Limit, 1 minute. + public TimeLimit() { + minutes = 1; + seconds = 0; + } + + public TimeLimit(int minutes, int seconds) { + checkArgument(isValidTimeLimit(minutes, seconds), MESSAGE_CONSTRAINTS); + this.minutes = minutes; + this.seconds = seconds; + } + + /** + * Ensure both minutes and seconds are between 0 and 60 + * The total time should be less than an hour + */ + private boolean isValidTimeLimit(int minutes, int seconds) { + if (seconds < 0 || minutes < 0 || seconds >= 60 || minutes >= 60) { + return false; + } + return true; + } + + @Override + public String toString() { + String minutesString = Integer.toString(minutes); + String secondsString = Integer.toString(seconds); + return minutesString + MESSAGE_AFTER_MINUTES + secondsString + MESSAGE_AFTER_SECONDS; + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof TimeLimit)) { + return false; + } + return minutes == ((TimeLimit) other).minutes && seconds == ((TimeLimit) other).seconds; + } + +} diff --git a/src/test/java/seedu/address/flashcard/CardIdTest.java b/src/test/java/seedu/address/flashcard/CardIdTest.java new file mode 100644 index 00000000000..4242918fdbb --- /dev/null +++ b/src/test/java/seedu/address/flashcard/CardIdTest.java @@ -0,0 +1,21 @@ +package seedu.address.flashcard; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +public class CardIdTest { + + private CardId id1 = new CardId(); + private CardId id2 = new CardId(); + private CardId id3 = new CardId(); + private CardId id4 = new CardId(); + + @Test + public void generateIdTest() { + assertEquals(0, id1.getIdentityNumber()); + assertEquals(1, id2.getIdentityNumber()); + assertEquals(2, id3.getIdentityNumber()); + assertEquals(3, id4.getIdentityNumber()); + } +}