Advertisement
Guest User

Contacts: 21/9/2017

a guest
Sep 21st, 2017
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. Contact:
  2. ------------
  3. package Telphon;
  4.  
  5. public class Contact {
  6. private String owner;
  7. private String family;
  8. private String number;
  9. private String email;
  10.  
  11. public Contact(String owner, String family, String number, String email) {
  12. super();
  13. this.owner = owner;
  14. this.family = family;
  15. this.number = number;
  16. this.email = email;
  17. }
  18.  
  19. public Contact(Contact t1) {
  20. this.owner = t1.owner;
  21. this.family = t1.family;
  22. this.number = t1.number;
  23. this.email = t1.email;
  24.  
  25. }
  26.  
  27. public String getOwner() {
  28. return owner;
  29. }
  30.  
  31. public void setOwner(String owner) {
  32. this.owner = owner;
  33. }
  34.  
  35. public String getEmail() {
  36. return email;
  37. }
  38.  
  39. public void setEmail(String email) {
  40. email = email;
  41. }
  42.  
  43. public String getFamily() {
  44. return family;
  45. }
  46.  
  47. public void setFamily(String family) {
  48. this.family = family;
  49. }
  50.  
  51. public String getNumber() {
  52. return number;
  53. }
  54.  
  55. public void setNumber(String number) {
  56. this.number = number;
  57. }
  58.  
  59. @Override
  60. public String toString() {
  61. return "Contact [owner=" + owner + ", family=" + family + ", number=" + number + ", email=" + email + "].";
  62. }
  63.  
  64. }
  65. Contact List:
  66. ---------------
  67.  
  68. package Telphon;
  69.  
  70. public class ContactList {
  71. final private int MAX_SIZE = 15;
  72. private Contact[] conts;
  73. private int count;
  74.  
  75. public ContactList() {
  76. conts = new Contact[MAX_SIZE];
  77. this.count = 0;
  78. }
  79.  
  80. public boolean addContact(Contact cont) {
  81. if (count < conts.length) {
  82. this.conts[count] = new Contact(cont);
  83. count += 1;
  84. return true;
  85. }
  86.  
  87. return false;
  88. }
  89.  
  90. public String toString() {
  91. String res = "";
  92. for (int i = 0; i < count; i += 1)
  93. res += conts[i] + "\n";
  94.  
  95. return res;
  96.  
  97. }
  98.  
  99. }
  100. Tester:
  101. -------------
  102. package Telphon;
  103.  
  104. import Telphon.Contact;
  105. import Telphon.ContactList;
  106.  
  107. public class Tester {
  108.  
  109. public static void main(String[] args) {
  110. System.out.println(" Contact List");
  111. System.out.println("..............");
  112. Contact S1 = new Contact("sajed", "Narane", "0548180960", "sajed_2000@gmail.com");
  113. Contact S2 = new Contact("Ameer", "mhmdat", "0546150490", "ameer_1998@gmail.com");
  114. Contact S3 = new Contact("Rami", "swaed", "0506182115", "abo_zeko@gmail.com");
  115. Contact S4 = new Contact("Asad", "Narane", "0538441879", "asad-na@gmail.com");
  116. Contact S5 = new Contact("Nora", "Deab", "0528260777", "nora_93@gmail.com");
  117.  
  118. ContactList sajed = new ContactList();
  119. ContactList Ameer = new ContactList();
  120. ContactList Rami = new ContactList();
  121. ContactList Asad = new ContactList();
  122. ContactList Nora = new ContactList();
  123.  
  124. sajed.addContact(S1);
  125. Ameer.addContact(S2);
  126. Rami.addContact(S3);
  127. Asad.addContact(S4);
  128. Nora.addContact(S5);
  129.  
  130. System.out.println(sajed);
  131. System.out.println(Ameer);
  132. System.out.println(Rami);
  133. System.out.println(Asad);
  134. System.out.println(Nora);
  135.  
  136. //System.out.println("-----------------------------");
  137. System.out.println(" / 5 contacts / ");
  138.  
  139. }
  140.  
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement