forked from nus-cs2103-AY1920S1/addressbook-level3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request nus-cs2103-AY1920S1#3 from Oscar-B-Liang/Liang_rec…
…ess_week Liang recess week
- Loading branch information
Showing
4 changed files
with
188 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |