Rachelle il y a 6 ans
Parent
révision
4617bcd5ae
2 fichiers modifiés avec 16 ajouts et 6 suppressions
  1. 11
    0
      Entry.java
  2. 5
    6
      PhoneBook.java

+ 11
- 0
Entry.java Voir le fichier

19
         phoneNumber.append(entryArray.get(entryArray.size()-1));
19
         phoneNumber.append(entryArray.get(entryArray.size()-1));
20
         return phoneNumber.toString();
20
         return phoneNumber.toString();
21
     }
21
     }
22
+    
23
+    public boolean hasPhoneNumber(String phoneNumber){
24
+        boolean hasPhoneNumber = false;
25
+            for(String number:entryArray){
26
+            if(phoneNumber.equals(number)){
27
+                hasPhoneNumber = true;
28
+                break;
29
+            }
30
+        }  
31
+        return hasPhoneNumber;
32
+    }
22
 
33
 
23
     public void addPhoneNumber(String phoneNumber){
34
     public void addPhoneNumber(String phoneNumber){
24
         entryArray.add(phoneNumber);
35
         entryArray.add(phoneNumber);

+ 5
- 6
PhoneBook.java Voir le fichier

41
                 if(reverseLookup(phoneNumber).equals("no match")){
41
                 if(reverseLookup(phoneNumber).equals("no match")){
42
                     System.out.println("\n**Number not found.**");
42
                     System.out.println("\n**Number not found.**");
43
                 }else{
43
                 }else{
44
-                    System.out.println("This is " + reverseLookup(phoneNumber) + "'s number.");
44
+                    System.out.println("\n**" + phoneNumber + " listed to:**\n" + reverseLookup(phoneNumber));
45
                 }
45
                 }
46
                 continueMessage();
46
                 continueMessage();
47
                 break;
47
                 break;
149
     }
149
     }
150
 
150
 
151
     public String reverseLookup(String number){
151
     public String reverseLookup(String number){
152
-        String nameForAGivenNumber = "no match";
152
+        StringBuilder personsWithGivenNumber = new StringBuilder();
153
         for(String name: phonebook.keySet()){
153
         for(String name: phonebook.keySet()){
154
             Entry entry = phonebook.get(name);
154
             Entry entry = phonebook.get(name);
155
-            String phoneNumber = entry.getPhoneNumber();
156
-            if (phoneNumber.equals(number)){
157
-                nameForAGivenNumber = name;
155
+            if (entry.hasPhoneNumber(number)){
156
+                personsWithGivenNumber.append(name + "\n");
158
             }
157
             }
159
         }
158
         }
160
-        return nameForAGivenNumber;
159
+        return personsWithGivenNumber.toString();
161
     }
160
     }
162
 
161
 
163
     //Deletion
162
     //Deletion