Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package repertoire;
- import repertoire.Contact;
- public class Repertoire {
- private Contact[] c;
- private int nbContact=0;
- public Repertoire() {
- c=new Contact[nbContact];
- }
- public void ajouter(Contact contact) {
- if(nbContact!= c.length) {
- c[nbContact]=contact;
- nbContact++;
- }
- }
- public Contact chercheNom(String nom) {
- for(int index=0;index<nbContact;index++){
- if(c[index].getNom().contentEquals(nom)) {
- return c[index];
- }
- }
- return null;
- }
- public Contact chercheTel(String tel) {
- for(int index=0;index < nbContact;index++){
- if(c[index].getTel().contentEquals(tel)) {
- return c[index];
- }
- }
- return null;
- }
- public void modifier(String nom,String newTel) {
- Contact c= chercheNom(nom);
- if(c!=null) {
- c.setTel(newTel);
- }
- }
- public void supprimer(String nom) {
- int index;
- //supprimer le contact
- for(index=0;index<nbContact;index++){
- if(c[index].getNom().contentEquals(nom)) {
- c[index]=null;
- break;
- }
- }
- //deplacer le contact suivant
- for(int newIndex = index;index<nbContact-1;index++) {
- c[newIndex]=c[newIndex+1];
- }
- if(index!=nbContact) {
- nbContact--;
- }
- }
- public String toString() {
- String result = "tous les contacts : \n";
- for (int index = 0; index < nbContact; index++) {
- result += c[index].toString() + "\n";
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement