Skip to content

Commit

Permalink
Merge pull request nus-cs2103-AY1920S1#3 from Oscar-B-Liang/Liang_rec…
Browse files Browse the repository at this point in the history
…ess_week

Liang recess week
  • Loading branch information
Oscar-B-Liang authored Sep 26, 2019
2 parents a7e0741 + af2675e commit 3807952
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/main/java/seedu/address/flashcard/CardId.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
52 changes: 52 additions & 0 deletions src/main/java/seedu/address/flashcard/Score.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
60 changes: 60 additions & 0 deletions src/main/java/seedu/address/flashcard/TimeLimit.java
Original file line number Diff line number Diff line change
@@ -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;
}

}
21 changes: 21 additions & 0 deletions src/test/java/seedu/address/flashcard/CardIdTest.java
Original file line number Diff line number Diff line change
@@ -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());
}
}

0 comments on commit 3807952

Please sign in to comment.