From c3c0cbfe7dd6922191991d3db43ea9ac7c98b3b0 Mon Sep 17 00:00:00 2001 From: kmitresse Date: Fri, 29 Mar 2024 09:44:54 +0100 Subject: [PATCH] fix: dev-web - initialize list of player (... = new arrayList<>()) in User and Game constructors --- S2/DevWeb/Projet/src/main/java/uppa/project/pojo/Game.java | 2 ++ S2/DevWeb/Projet/src/main/java/uppa/project/pojo/User.java | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/S2/DevWeb/Projet/src/main/java/uppa/project/pojo/Game.java b/S2/DevWeb/Projet/src/main/java/uppa/project/pojo/Game.java index c8a95a6..2cffee8 100644 --- a/S2/DevWeb/Projet/src/main/java/uppa/project/pojo/Game.java +++ b/S2/DevWeb/Projet/src/main/java/uppa/project/pojo/Game.java @@ -91,6 +91,8 @@ public class Game implements Serializable { this.nbValuesPerColor = nbValuesPerColor; this.deck = new Deck(nbColors, nbValuesPerColor); this.deck.shuffle(); + this.players = new ArrayList<>(); + this.createdAt = new Date(); } /** diff --git a/S2/DevWeb/Projet/src/main/java/uppa/project/pojo/User.java b/S2/DevWeb/Projet/src/main/java/uppa/project/pojo/User.java index ec78df3..8cccbb4 100644 --- a/S2/DevWeb/Projet/src/main/java/uppa/project/pojo/User.java +++ b/S2/DevWeb/Projet/src/main/java/uppa/project/pojo/User.java @@ -91,6 +91,7 @@ public class User implements Serializable { this.password = hashPassword(password); this.birth = birth; this.gender = gender; + this.playedGames = new ArrayList<>(); } /** @@ -288,6 +289,7 @@ public class User implements Serializable { * @return le pourcentage de victoire */ public double getWinRate(){ + if (getNbPlayedGame() == 0 || getNbWin() == 0) return 0; return (double) Math.abs(getNbWin() * 10000 / getNbPlayedGame()) /100; } @@ -323,6 +325,7 @@ public class User implements Serializable { * @return le pourcentage de clics réussi */ public double getRightClickPercentRate(){ + if (getNbClicks() == 0 || getNbRightClicks() == 0) return 0; return (double) Math.abs(getNbRightClicks() * 10000 / getNbClicks())/100; } @@ -345,11 +348,15 @@ public class User implements Serializable { * @return le pourcentage de clics les plus rapides */ public double getRapidClickPercentRate(){ + if (getNbClicks() == 0 || getNbRapidClicks() == 0) return 0; return (double) Math.abs(getNbRapidClicks() * 10000 / getNbClicks())/100; } public boolean isValidBirthDate(Date birthdate){ + System.out.println(birthdate.toString()); + Date currentDate = new Date(); + System.out.println(currentDate.toString()); return birthdate.before(currentDate) || birthdate.equals(currentDate); }