brouillon un peu mieux de ReservationFactoryNP -- disclaimer : use at your own risk

This commit is contained in:
Florent Madelaine 2021-10-22 18:57:48 +02:00
parent 20012ff5d1
commit 2a124a8934
3 changed files with 67 additions and 18 deletions

View File

@ -53,6 +53,7 @@ ${BUILD}/API/Prereservation.class : ${SRC}/API/Prereservation.java \
${JAVAC} ${JAVAC_OPTIONS} ${SRC}/API/Prereservation.java
${BUILD}/API/Reservation.class : ${SRC}/API/Reservation.java \
${BUILD}/API/Chambre.class \
${BUILD}/API/Prereservation.class
${JAVAC} ${JAVAC_OPTIONS} ${SRC}/API/Reservation.java
@ -61,7 +62,7 @@ ${BUILD}/API/PrereservationFactory.class : ${SRC}/API/PrereservationFactory.java
${JAVAC} ${JAVAC_OPTIONS} ${SRC}/API/PrereservationFactory.java
${BUILD}/API/ReservationFactory.class : ${SRC}/API/ReservationFactory.java \
${BUILD}/API/Prereservation.class
${BUILD}/API/Reservation.class
${JAVAC} ${JAVAC_OPTIONS} ${SRC}/API/ReservationFactory.java
## MNP ##
@ -83,18 +84,22 @@ ${BUILD}/MNP/ReservationNP.class : ${SRC}/MNP/ReservationNP.java \
${BUILD}/API/Reservation.class
${JAVAC} ${JAVAC_OPTIONS} ${SRC}/MNP/ReservationNP.java
${BUILD}/MNP/PrereservationFactory.class : ${SRC}/API/PrereservationFactory.java
${JAVAC} ${JAVAC_OPTIONS} ${SRC}/MNP/PrereservationFactory.java
${BUILD}/MNP/PrereservationFactoryNP.class : ${SRC}/MNP/PrereservationFactoryNP.java \
${BUILD}/API/PrereservationFactory.class
${JAVAC} ${JAVAC_OPTIONS} ${SRC}/MNP/PrereservationFactoryNP.java
${BUILD}/MNP/ReservationFactoryNP.class : ${SRC}/MNP/ReservationFactoryNP.java \
${BUILD}/MNP/ChambreNP.class \
${BUILD}/MNP/ReservationNP.class \
${BUILD}/API/ReservationFactory.class
${JAVAC} ${JAVAC_OPTIONS} ${SRC}/MNP/ReservationFactoryNP.java
## TEST ##
${BUILD}/Test/TestTexteMNP.class : ${SRC}/Test/TestTexteMNP.java \
${BUILD}/MNP/PrereservationNP.class \
${BUILD}/MNP/PrereservationFactoryNP.class
${BUILD}/MNP/PrereservationFactoryNP.class \
${BUILD}/MNP/ReservationFactoryNP.class
${JAVAC} -Xlint:deprecation ${JAVAC_OPTIONS} ${SRC}/Test/TestTexteMNP.java
# ## JARS ##

View File

@ -29,15 +29,17 @@ public class ReservationFactoryNP implements ReservationFactory{
// similaire pour stocker la valeur max, même un hotel magique devrait faire le ménage.
private EnumMap<TypeChambre,Integer> brokenMagic;
// BUGFIX. ^ c'est le xor en java donc 10^6 ça ne fait pas un million mais autre chose
// Du coup en dessous j'écris 1000000 à la place.
// plus petite et plus grande valeur pour les chambres UNLS
private static int MIN_UNLS = 0;
private static int MAX_UNLS = 10^6 -1;
private static int MAX_UNLS = 1000000 -1;
// plus petite et plus grande valeur pour les chambres DEUXLS
private static int MIN_DEUXLS = 10^6;
private static int MAX_DEUXLS = 2*10^6 -1;
private static int MIN_DEUXLS = 1000000;
private static int MAX_DEUXLS = 2*1000000 -1;
// plus petite et plus grande valeur pour les chambres UNLD
private static int MIN_UNLD = 2*10^6;
private static int MAX_UNLD = 3*10^6 -1;
private static int MIN_UNLD = 2*1000000;
private static int MAX_UNLD = 3*1000000 -1;
// plus grand nombre de chambres à proposer si le client souhaite choisir (va automatiquement salir les chambres précédentes)
private static int ADEQUATE = 5;
@ -143,7 +145,7 @@ public class ReservationFactoryNP implements ReservationFactory{
int howMany = Math.min(this.brokenMagic.get(p.getTypeChambre()) - this.nextFreeRoom.get(p.getTypeChambre()), this.ADEQUATE);
for (int i=0; i< howMany ;i++) {
Chambre c = new ChambreNP(numero,p.getTypeChambre());
Chambre c = new ChambreNP(numero+i,p.getTypeChambre());
res.add(c);
}
@ -184,7 +186,13 @@ public class ReservationFactoryNP implements ReservationFactory{
this.brain.put(d,s);
}
public String prochainesChambresLibres(){
StringBuilder sb = new StringBuilder("prochaines chambres libres par type:\n");
for (TypeChambre t : TypeChambre.values()){
sb.append("\t _ " + t + " " + this.nextFreeRoom.get(t) + "\n");
}
return sb.toString();
}
/**
* Fabrique (ajoute) une réservation
@ -203,9 +211,9 @@ public class ReservationFactoryNP implements ReservationFactory{
if (c.getType()!=p.getTypeChambre()) {
throw new IllegalArgumentException("Erreur sur le type de la chambre: la préréservation indique " + p.getTypeChambre() + " mais la chambre est " + c.getType());
}
else if (false) // n'arrive jamais dans l'hôtel magique.
else if (false) // on fait comme si ça n'arrive jamais dans l'hôtel magique (pour l'instant).
{
throw new IllegalArgumentException("Pas de chambre disponible de type " + p.getTypeChambre());
throw new IllegalArgumentException("La chambre " + c.monPrint() + " n'est pas disponible pour fabriquer une réservation à partir de la préréservation " + p.monPrint());
}
else {
Reservation r = new ReservationNP(p.getReference(), p.getDateDebut(), p.getJours(), c, p.getClient());

View File

@ -3,6 +3,7 @@ import fr.iutfbleau.projetIHM2021FI2.API.*;
import fr.iutfbleau.projetIHM2021FI2.MNP.*;
import java.time.LocalDate;
import java.util.*;
//import java.util.Random;
public class TestTexteMNP{
@ -52,6 +53,8 @@ public class TestTexteMNP{
// On peut donc changer l'implémentation du modèle tant qu'on ne change pas l'API en préservant le bon fonctionement de la vue et du controleur.
// Pour l'instant, nous n'avons ni vue, ni controleur, mais nous pouvons faire semblant en interagissant avec le modèle via l'API.
// pour choisir au hasard.
Random random = new Random();
System.out.print("Simulation manuelle du genre de chose que la vue pourrait faire.\n");
@ -99,6 +102,39 @@ public class TestTexteMNP{
System.out.print("I found your bookings.\n");
for(Prereservation p : preresas){
System.out.println(p.monPrint());
Chambre libre = null;
Set<Chambre> disponibles=null;
try{
disponibles = grandLivreDOrAPISeulement.getChambres(p);
System.out.print("I have great rooms for you :\n");
for(Chambre c : disponibles){
System.out.println(c.monPrint());
}
// choix de la chambre au hasard simulant le choix du client
int choix = random.nextInt(disponibles.size());
System.out.println("choix: " + choix);
int compter = 0;
for(Chambre c : disponibles){
if (compter == choix){
libre = c;
break;
}
compter++;
}
}
catch(IllegalStateException e){
System.out.print(e.getMessage());
}
try{
System.out.println(libre.monPrint());
System.out.print("You like this room? Excellent! Let me confirm the reservation for you.\n");
Reservation resa = grandLivreDOrAPISeulement.createReservation(p,libre);
System.out.println(resa.monPrint());
}
catch(IllegalStateException e){
System.out.print(e.getMessage());
}
}
}
catch(IllegalStateException e){