Objet a mettre devant une methode

Résolu
hedii Messages postés 43 Statut Membre -  
 hedii -
Bonjour

Pour la methode rechercherNom que mettre devant, dans la classe testannuaire?

Et pour les constructeur des classes annuaire et numerotel et abonee puis je les laisser vide?

3 réponses

  1. hedii Messages postés 43 Statut Membre
     
    Revoici les classes:

    package tp2ex2;
    import java.util.Hashtable;
    import java.util.NoSuchElementException;
    /**
    *
    * @author 12mi143
    */
    public class Annuaire {

    Hashtable parNoms = new Hashtable();
    Hashtable parNumeros = new Hashtable();

    /** Creates a new instance of Annuaire */
    public Annuaire() {
    }

    public void ajouter(String nom, NumeroTel numero) {
    parNoms.put(nom, numero);
    parNumeros.put(numero, nom);
    }

    public Object rechercheNom (NumeroTel numero) throws NoSuchElementException {

    if (parNumeros.containsValue(numero)){
    return parNoms.get(numero);
    }
    else
    {
    throw new NoSuchElementException ();
    }
    }

    public Object rechercheNumero (String nom) throws NoSuchElementException {

    if (parNoms.containsValue(nom)){
    return parNumeros.get(nom);
    }
    else
    {
    throw new NoSuchElementException ();
    }
    }

    public String toString() {
    return "Annuaire par noms:"+parNoms+"Annuaire par numeros:"+parNumeros;
    }

    }

    package tp2ex2;

    /**
    *
    * @author 12mi143
    */
    public class NumeroTel {

    private NumeroTel numero;
    private int a;
    private int b;
    private int c;
    private int d;
    private int e;
    /** Creates a new instance of NumeroTel */
    public NumeroTel(int a,int b,int c,int d,int e) {
    }

    public boolean Comparaison (NumeroTel numero1) {
    if (numero.equals(numero1)){
    return true;
    }
    else {
    return false;
    }
    }

    public NumeroTel getNumero() {
    return numero;
    }

    public String toString() {
    return ""+numero;
    }

    }

    package tp2ex2;

    /**
    *
    * @author 12mi143
    */
    public class Abonne {

    private String nom;
    private NumeroTel numero;

    /** Creates a new instance of Abonne */
    public Abonne() {

    }

    public String getNom() {
    return nom;
    }

    public NumeroTel getNumero() {
    return numero;
    }

    public String toString () {
    return ""+nom+numero;
    }
    }

    package tp2ex2;
    import java.util.Hashtable;
    import java.util.NoSuchElementException;
    /**
    *
    * @author FOUFA
    */
    public class TestAnnuaire {

    public static void main(String[] args) {

    Annuaire annuaire = new Annuaire();

    Hashtable parNoms = new Hashtable();
    Hashtable parNumeros = new Hashtable();

    String nom1 = "personne1";

    annuaire.ajouter(nom1, new NumeroTel(0,1,2,3,4));
    annuaire.ajouter(nom1, new NumeroTel(0,1,2,3,4));

    try {
    parNoms.rechercheNom(0,1,1,1,1);
    }

    catch (NoSuchElementException e) {
    System.out.println("Pas de personne correspondante");
    }

    try {
    parNumeros.rechercheNumero(nom1);
    }

    catch (NoSuchElementException e) {
    System.out.println("Pas de numero correspondant");
    }

    }
    }
    0
  2. hedii
     
    J'ai compri pour l'objet a mettre devant les methodes, mais pour les constructeurs vides est e correct ?

    merci !
    0
  3. hedii
     
    up, les constructeur vides est ce correct ?

    merci!
    0
    1. KX Messages postés 19031 Statut Modérateur 3 020
       
      C'est correct, mais c'est déjà le comportement par défaut, donc si tu ne mets rien ça ferait pareil.
      0
    2. hedii
       
      merci
      0