You are on page 1of 1

export class Chambre {private _nom:string;private _nbreLit:number;private _vue:string;

public get nom():string {return this._nom;}public set nom(value:string) {this._nom = value;}


public get nbreLit():number {return this._nbreLit;}
public set nbreLit(value:number) {this._nbreLit = value;}
public get vue():string {return this._vue;}
public set vue(value:string) {this._vue = value;}
constructor(nom:string, nbreLit:number, vue:string) {this._nom = nom;this._nbreLit =
((nbreLit>0)&&(nbreLit<=4))?nbreLit:1;this._vue = (vue in ["VJ","VM","VP"])?vue:"VJ";}}
import { Chambre } from "./Chambre";
export class Hotel{private _nom:string;private _chambres:Chambre[];private _etoil:number;
public get nom():string { return this._nom;}public set nom(value:string) {this._nom = value;}
public get chambres():Chambre[] {return this._chambres;}
public set chambres(value:Chambre[]) {this._chambres = value;}public get etoil():number {return this._etoil;}
public set etoil(value:number) {this._etoil = value;}
constructor(nom:string,etoil:number,chambres:Chambre[]) {this._nom = nom;this._chambres = chambres;
this._etoil = ((etoil>0)&&(etoil<=5))?etoil:1;}}
import { Hotel } from "./Hotel";
export class ListeHotels{private _hotels:Hotel[];
public get hotels():Hotel[] {return this._hotels;}public set hotels(value:Hotel[]) {this._hotels = value;}
constructor(hotels:Hotel[]) {this._hotels = hotels;}
public getByName(nom:string):Array<object>{return this._hotels.filter((hotel)=>hotel.nom==nom);}
public getByEtoil(etoil:number):Array<object>{return this._hotels.filter((hotel)=>hotel.etoil==etoil);}
public countChambre():Array<object>{
return this._hotels.map((hotel)=>{return {"nom":hotel.nom,"nombre de chambre":hotel.chambres.length}});}
public countByChambre(chambre:string):number{
return this._hotels.filter((hotel)=>hotel.chambres.map(c=>c.nom).indexOf(chambre) != -1).length;}
public editHotelNom(oldNom:string,newNom:string):void{for(let hotel of this._hotels){if(hotel.nom==oldNom){
hotel.nom=newNom;}}}
public editHotelEtoilByNom(nom:string,etoil:number):void{for(let hotel of this._hotels){if(hotel.nom==nom){
hotel.etoil=etoil;}}}}
import { Chambre } from "./Chambre";import { Hotel } from "./Hotel";import { ListeHotels } from "./ListeHotels";
QUESTION 3
let hotel1 = new Hotel("Joya Paradise",4,[new Chambre("Double",2,"VM"),new Chambre("Triple",3,"VP")]);
console.log("\nHotel 1 crée");console.log(hotel1);
let hotel2 = new Hotel("Meninx",3,[new Chambre("Single",1,"VJ"),new Chambre("Double",2,"VM")]);
console.log("\nHotel 2 crée");console.log(hotel2);
QUESTION 4///let lh = new ListeHotels([hotel1,hotel2]);console.log("Liste Hotels crée");
QUESTION 5///console.log(lh.getByName("Meninx"));
QUESTION 6///console.log(JSON.stringify(lh.getByEtoil(4)));
QUESTION 7///console.log(lh.countChambre());
QUESTION 8///console.log(lh.countByChambre("Single"))
QUESTION 9///console.log("Nom du hotel avant changement:",hotel1.nom);console.log("-------changement--------");
lh.editHotelNom("Joya Paradise","Zita zarzis");console.log("Nom du hotel apres changement:", hotel1.nom);
QUESTION 10///console.log("Nombre d'etoiles de",hotel2.nom,"avant changement",hotel2.etoil);
console.log("---------changement--------");
lh.editHotelEtoilByNom("Meninx",4);
console.log("Nombre d'etoiles de",hotel2.nom,"apres changement", hotel2.etoil);

You might also like