Advertisement
Guest User

pour THO MAS

a guest
Oct 21st, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. package repertoire;
  2. import repertoire.Contact;
  3.  
  4. public class Repertoire {
  5.  
  6. private Contact[] c;
  7. private int nbContact=0;
  8.  
  9. public Repertoire() {
  10. c=new Contact[nbContact];
  11. }
  12.  
  13. public void ajouter(Contact contact) {
  14. if(nbContact!= c.length) {
  15. c[nbContact]=contact;
  16. nbContact++;
  17. }
  18. }
  19.  
  20. public Contact chercheNom(String nom) {
  21. for(int index=0;index<nbContact;index++){
  22. if(c[index].getNom().contentEquals(nom)) {
  23. return c[index];
  24. }
  25. }
  26. return null;
  27. }
  28.  
  29. public Contact chercheTel(String tel) {
  30. for(int index=0;index < nbContact;index++){
  31. if(c[index].getTel().contentEquals(tel)) {
  32. return c[index];
  33. }
  34. }
  35. return null;
  36. }
  37.  
  38. public void modifier(String nom,String newTel) {
  39. Contact c= chercheNom(nom);
  40. if(c!=null) {
  41. c.setTel(newTel);
  42. }
  43. }
  44.  
  45. public void supprimer(String nom) {
  46. int index;
  47. //supprimer le contact
  48. for(index=0;index<nbContact;index++){
  49. if(c[index].getNom().contentEquals(nom)) {
  50. c[index]=null;
  51. break;
  52. }
  53. }
  54. //deplacer le contact suivant
  55. for(int newIndex = index;index<nbContact-1;index++) {
  56. c[newIndex]=c[newIndex+1];
  57. }
  58. if(index!=nbContact) {
  59. nbContact--;
  60. }
  61. }
  62.  
  63. public String toString() {
  64. String result = "tous les contacts : \n";
  65. for (int index = 0; index < nbContact; index++) {
  66. result += c[index].toString() + "\n";
  67. }
  68. return result;
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement