コード例 #1
0
 private void carregaPreuTipusHabitacions() {
   String[] nomsHotels = {
     "Palace", "Hilton", "Metropolitan", "Arts", "Catalunya", "Pensión Pepe", "Bonjour", "Oulala"
   };
   String[] nomsTipus = {"Individual", "Doble", "Matrimoni"};
   float[] preus = {100, 200, 250};
   for (int i = 0; i < nomsHotels.length; ++i) {
     for (int j = 0; j < nomsTipus.length; ++j) {
       PreuTipusHabitacio pth = new PreuTipusHabitacio();
       pth.setId(new PreuTipusHabitacioId(nomsHotels[i], nomsTipus[j]));
       pth.setPreu(preus[j]);
       if (j == 0) {
         AbsoluteDiscountPreuStrategy adps = new AbsoluteDiscountPreuStrategy();
         adps.setId(new PreuTipusHabitacioId(nomsHotels[i], nomsTipus[j]));
         adps.setDescompte(30);
         pth.setStrategy(adps);
         session.saveOrUpdate(pth);
         session.saveOrUpdate(adps);
       } else {
         PercentDiscountPreuStrategy pdps = new PercentDiscountPreuStrategy();
         pdps.setId(new PreuTipusHabitacioId(nomsHotels[i], nomsTipus[j]));
         pdps.setPerc(0.7F);
         pth.setStrategy(pdps);
         session.saveOrUpdate(pth);
         session.saveOrUpdate(pdps);
       }
     }
   }
 }
コード例 #2
0
ファイル: Hotel.java プロジェクト: jordisala1991/BonsHotels
 public ReservaInformation seleccionarHabitacio(Date dIni, Date dFi, String tipusHab) {
   ReservaInformation res = new ReservaInformation();
   Float preu = new Float(0);
   Integer numHab = new Integer(0);
   Iterator<PreuTipusHabitacio> it = preuTipusHabitacio.iterator();
   while (it.hasNext()) {
     PreuTipusHabitacio pth = it.next();
     if (pth.esDelTipus(tipusHab)) {
       preu = pth.obtePreu();
       numHab = pth.obteHabitacio(dIni, dFi, nom);
       break;
     }
   }
   res.setPreuTotal(preu * ((dFi.getTime() - dIni.getTime()) / MILLSECS_PER_DAY));
   res.setNumHab(numHab);
   return res;
 }
コード例 #3
0
ファイル: Hotel.java プロジェクト: jordisala1991/BonsHotels
 public HotelInformation buscarHabsHotel(Date dIni, Date dFi, Integer numOcup) {
   HotelInformation hotel = new HotelInformation();
   Set<TipusHabInformation> habs = new HashSet<TipusHabInformation>();
   Iterator<PreuTipusHabitacio> it = preuTipusHabitacio.iterator();
   while (it.hasNext()) {
     PreuTipusHabitacio pth = it.next();
     TipusHabInformation thab = pth.obteDisponiblesDelTipus(dIni, dFi, numOcup, nom);
     if (thab.getNum() > 0) habs.add(thab);
   }
   Iterator<Comentari> it2 = comentari.iterator();
   Float av = new Float(0);
   while (it2.hasNext()) av += it2.next().getAvaluacio();
   hotel.setNomHotel(nom);
   hotel.setDesc(descripcio);
   hotel.setCategoria(categoriaHotel.getNom());
   if (comentari.size() > 0) hotel.setAvaluacio(av / comentari.size());
   hotel.setHabs(habs);
   return hotel;
 }