Bonjour,
voilà le but est de créer une agence qui gère une liste de propriétaire qui travaille avec elle et une liste de local (entreprise) et de logement (particulier).
nouveauProprio->ajoute un propriétaire à la liste des propriétaires de l'agence
nouveauLogement,nouveauLocal->ajoute un logement à la liste des logements de l'agence et met à jour la liste des locations que le propriétaire possède (si le propriétaire ne fait pas partie de la liste il doit levé une exception)
rechercheLogement->renvoie la liste des logements adapté à la demande du client (avec jardin ou sans / avec un certain nombre de chambre)
Ma classe agence:
Ma classe proprietaire:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66 public class agence{ private proprietaire[] tabProprio; private local[] tabLoc; private logement[] tabLog; private static final int MAX=100; private int nbProprio=0; private int nbLoc=0; private int nbLog=0; public agence(){ tabProprio=new proprietaire[MAX]; tabLoc=new local[MAX]; tabLog=new logement[MAX]; } public void nouveauProprio(String nom,String prenom,String adresse){ if(nbProprio<MAX) tabProprio[nbProprio++]=new proprietaire(nom,prenom,adresse); } public boolean nouveauLogement(float loyer,float charge,float superficie,String adresse, String proprio,int nbChambres,boolean jardin)throws ProprietaireInconnuException{ tabLog[nbLog++]=new logement(loyer,charge,superficie,adresse,proprio,nbChambres,jardin); for(int i=0;i<nbProprio;i++) if(tabProprio[i].getNom().equals(proprio)){ tabProprio[i].ajouteLocation(loyer,charge,superficie,adresse); return true; } throw new ProprietaireInconnuException(); } public boolean nouveauLocal(float loyer,float charge,float superficie,String adresse, String proprio,String descriptif)throws ProprietaireInconnuException{ tabLoc[nbLoc++]=new local(loyer,charge,superficie,adresse,proprio,descriptif); for(int i=0;i<nbProprio;i++) if(tabProprio[i].getNom().equals(proprio)){ tabProprio[i].ajouteLocation(loyer,charge,superficie,adresse); return true; } throw new ProprietaireInconnuException(); } public logement[] rechercheLogement(int nbChambre,boolean jardin){ logement[] tab=new logement[100]; int nbL=0; for(int i=0;i<nbLog;i++) if(tabLog[i].getNbChambres().equals(nbChambre) && tabLog[i].getJardin().equals(jardin)) tab[nbL++]=tabLog[i]; return tab; } public String toString(){ StringBuilder tmp=new StringBuilder(); tmp.append("Liste des locations de l'agence\n"); tmp.append("Local:\n"); for(int i=0;i<nbLoc;i++) tmp.append(tabLoc[i]+"\n"); tmp.append("logement:\n"); for(int i=0;i<nbLog;i++) tmp.append(tabLog[i]+"\n"); tmp.append("Liste des locations des propriétaire qui tavaille avec l'agence\n"); for(int i=0;i<nbProprio;i++) tmp.append(tabProprio[i]); return tmp.toString(); } }
ma classe pour l'exception:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 public class proprietaire{ private String nom; private String prenom; private String adresse; private location[] tabLoc; private int nbLoc=0; private static final int MAXLOC=10; public proprietaire(String nom,String prenom,String adresse){ this.nom=nom; this.prenom=prenom; this.adresse=adresse; tabLoc=new location[MAXLOC]; } public String getNom(){ return nom; } public String getPrenom(){ return prenom; } public void ajouteLocation(float loyer,float charge,float superficie,String adresse){ tabLoc[nbLoc++]=new location(loyer,charge,superficie,adresse,nom); } public String toString(){ StringBuilder tmp=new StringBuilder(); tmp.append("Propriétaire:"); tmp.append(nom+" "+prenom+"\n"); tmp.append("Adresse:"+adresse+"\n"); tmp.append("propriétés:\n"); for(int i=0;i<nbLoc;i++) tmp.append(tabLoc[i]+"\n"); return tmp.toString(); } }
Ma classe pour test tous sa:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 public class ProprietaireInconnuException extends Exception{ public ProprietaireInconnuException(){ super("Ce propriétaire n'existe pas"); } }
voilà les erreurs:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 public class test{ public static void main(String[] args){ agence a=new agence(); a.nouveauProprio("ROLAND","Nicolas","7 rue des eaux"); a.nouveauProprio("SENTENZA","Delnir","8 rue des lys"); a.nouveauLogement(835f,150f,50f,"5 rue des magnolia","ROLAND",4,true); System.out.println(a); } }
agence.java:45: int cannot be dereferenced
if(tabLog[i].getNbChambres().equals(nbChambre) && tabLog[i].getJardin().equals(jardin))
^
agence.java:45: boolean cannot be dereferenced
if(tabLog[i].getNbChambres().equals(nbChambre) && tabLog[i].getJardin().equals(jardin))
et quand j'execute la classe test sans la méthode rechercheLogement ->
unreported exception ProprietaireInconnuException; must be caught or declared to be thrown
a.nouveauLogement(835f,150f,50f,"5 rue des magnolia","ROLAND",4,true);
pourquoi est-je ces erreurs?
j'ai probablement mal comprit les exeptions comment l'utiliser dans mon cas précis?
Partager