@Test
  public void testPersistence() {
    try {

      em.getTransaction().begin();

      Student u = new Student();
      u.setScore(12);
      u.setName("eskatos");

      em.persist(u);
      assertTrue(em.contains(u));

      em.remove(u);

      assertFalse(em.contains(u));

      em.getTransaction().commit();

    } catch (Exception ex) {
      em.getTransaction().rollback();
      ex.printStackTrace();
      fail("Exception during testPersistence");
    }
  }
 /** Method run in case of wrong answer. */
 private void answeredWrongly() {
   student.increaseNumberOfWrongAnswers();
   if (student.getNumberOfWrongAnswers() >= 9) {
     student.setNumberOfWrongAnswers(0);
     changeDifficulty(student.getDifficulty() - 1);
   }
 }
 /** Method run in case of correct answer. */
 private void answeredCorrectly() {
   increaseScore();
   student.increaseNumberOfCorrectAnswers();
   if (student.getNumberOfRightAnswers() >= 9) {
     changeDifficulty(student.getDifficulty() + 1);
     student.setNumberOfRightAnswers(0);
   }
 }
 /**
  * Sets the desired difficulty.
  *
  * @param difficulty Integer; 1-10
  */
 public void changeDifficulty(int difficulty) {
   student.setDifficulty(difficulty);
   this.questionsController =
       new QuestionsController(10, student.getDifficulty(), student.getOperationType());
 }
 /**
  * Sets a new score for the student.
  *
  * @param newScore Integer. The new score to set.
  */
 public void setScore(int newScore) {
   student.setScore(newScore);
 }
 /** @return Returns the students score. */
 public int getScore() {
   return student.getScore();
 }
 /** @return The players username. */
 public String getPlayerName() {
   return student.getName();
 }
 /** When called; increases the students score by the amount set in REWARD_SCORE (10) */
 protected void increaseScore() {
   student.setScore(student.getScore() + REWARD_SCORE);
 }
 /** @param student An Object of the class Student. */
 public GameController(Student student) {
   this.student = student;
   this.questionsController =
       new QuestionsController(10, student.getDifficulty(), student.getOperationType());
 }
Esempio n. 10
0
 /**
  * ADDITION = 0; SUBTRACTION = 1; MULTIPLICATION = 2; DIVISION = 3;
  *
  * @param playerName The students username
  * @param operationType Desired operation type; addition, substraction, multiplication, division.
  * @param difficulty Desired difficulty at game start. Will dynamically change to accomodate the
  *     students skill-level.
  */
 public GameController(String playerName, int operationType, int difficulty) {
   student = new Student(playerName);
   student.setOperationType(operationType);
   this.questionsController = new QuestionsController(10, difficulty, operationType);
   restoreGame();
 }