Build a simple PhoneBook program.

Entry.java 603B

1234567891011121314151617181920212223
  1. import java.util.ArrayList;
  2. import java.util.List;
  3. public class Entry
  4. {
  5. String name;
  6. String phoneNumber;
  7. List<String> entryArray = new ArrayList <String>();
  8. public Entry(String phoneNumber){
  9. entryArray.add(0,phoneNumber);
  10. }
  11. public String getPhoneNumber(){
  12. StringBuilder phoneNumber = new StringBuilder();
  13. for(int i = 0; i < entryArray.size(); i++){
  14. phoneNumber.append(entryArray.get(i));
  15. if(entryArray.size() > 1){
  16. phoneNumber.append(", ");
  17. }
  18. }
  19. return phoneNumber.toString();
  20. }
  21. }