public class Cours implements Comparable{ // cours avec son nom et son titre // on n'utilise que son nom pour l'identifier String nom, titre; // accès aux champs Cours(String nom, String titre){ if (nom==null) throw new NullPointerException(); this.nom = nom; this.titre = titre; } Cours(String nom){ this(nom,""); } public String toString(){ return nom; } // égalité et comparaison ne sont vérifiées que sur le nom du cours public boolean equals( Object that ) { if(that==this) return true; if(!(that instanceof Cours)) return false; return nom.equals( ((Cours) that).nom ); } public int hashCode(){ return nom.hashCode(); } public int compareTo(Cours that){ if(that==this) return 0; if(that==null) throw new NullPointerException(this+" comparé avec null"); return nom.compareTo(that.nom); } // accès aux champs public String getNom(){ return nom; } public String getTitre(){ return titre; } }