001 002 003 004import java.util.Set; 005import java.util.HashMap; 006/** 007 * classe ItemList 008 * 009 * @author Gabriel Leroux 010 * @version 23/03/20 011 */ 012public class ItemList 013{ 014 015 private HashMap <String,Item> aListeItem; 016 017 /** 018 * Constructeur d'objets de classe ItemList 019 * Instancie la HashMap 020 */ 021 public ItemList() 022 { 023 aListeItem=new HashMap<String,Item>(); 024 } 025 026 /** 027 * Rajouter un item dans la HashMap 028 * @param pString String du nom de l'item 029 * @param pItem Item associé à son nom 030 */ 031 public void addItem(final String pString, final Item pItem) 032 { 033 aListeItem.put(pString,pItem); 034 } 035 /** 036 * Accesseur de la HashMap aListeItem 037 * @param pString nom de l'item dont on veut retourner l'item concerné 038 * @return L'item associé au nom au paramètre 039 */ 040 public Item getItem(final String pString ){ 041 return aListeItem.get(pString); 042 } 043 /** 044 * Accesseur de la HashMap aListeItem 045 * @param pString nom du beamer dont on veut retourner le beamer concerné 046 * @return Le beamer associé au nom au paramètre 047 */ 048 public Beamer getBeamer(final String pString ){ 049 if (aListeItem.get(pString) instanceof Beamer){ 050 return (Beamer)aListeItem.get(pString); 051 } 052 else{ return null;}//pris en charge par le try catch de la methode goRoom 053 } 054 /** 055 * Enlever un item de la liste apres l'avoir déposer 056 * @param pString nom de l'item à supprimer 057 */ 058 public void suppItem(final String pString){ 059 aListeItem.remove(pString); 060 } 061 062 /** 063 * sers à afficher les items présents dans la pièce. 064 * @return la liste des items présents dans la salle 065 */ 066 public String returnListItem(){ 067 if (this.aListeItem==null){ 068 return "Il n'y a pas d'objet dans cette salle."; 069 } 070 else{ 071 String vRetour = ""; 072 073 Set <String> vItemm=aListeItem.keySet(); 074 for(String vItem : vItemm){ 075 vRetour+=aListeItem.get(vItem).getItem()+ " / "; 076 077 } 078 return vRetour ;} 079 } 080 /** 081 * Affiche poids total 082 * @return le prix total des objets de l'inventaire 083 */ 084 public String returnPoidsTot(){ 085 int vPoidsTotal=0; 086 Set <String> vItemm=aListeItem.keySet(); 087 for(String vItem : vItemm){ 088 vPoidsTotal+=aListeItem.get(vItem).getPrix(); 089 } 090 return "\n Le prix total de votre inventaire est de : "+ vPoidsTotal; 091 092 } 093}