Build a simple PhoneBook program.

Entry.java 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import java.util.ArrayList;
  2. import java.util.List;
  3. public class Entry
  4. {
  5. String phoneNumber;
  6. List<String> entryArray = new ArrayList <String>();
  7. public Entry(String phoneNumber){
  8. entryArray.add(0,phoneNumber);
  9. }
  10. public String getPhoneNumber(){
  11. StringBuilder phoneNumber = new StringBuilder();
  12. if(entryArray.size()>1){
  13. for(int i = 0; i < entryArray.size()-1; i++){
  14. phoneNumber.append(entryArray.get(i) + ", ");
  15. }
  16. }
  17. phoneNumber.append(entryArray.get(entryArray.size()-1));
  18. return phoneNumber.toString();
  19. }
  20. public void addPhoneNumber(String phoneNumber){
  21. entryArray.add(phoneNumber);
  22. }
  23. public boolean entryArrayContainsNumber(String phonenumber){
  24. boolean containsNumber = false;
  25. if(entryArray.contains(phonenumber)){
  26. containsNumber = true;
  27. }
  28. return containsNumber;
  29. }
  30. public int getNumberOfRecords(){
  31. return entryArray.size();
  32. }
  33. public void removePhoneNumber(String phoneNumber){
  34. for(String number:entryArray){
  35. if(phoneNumber.equals(number)){
  36. entryArray.remove(number);
  37. break;
  38. }
  39. }
  40. }
  41. }