Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. class AddressBook{
  2. private Person[] entry;
  3. private static int count;
  4.  
  5. AddressBook(){
  6.  
  7. }
  8. AddressBook(int i){
  9. entry=new Person[i];
  10. }
  11. public void addPerson(Person p){
  12. entry[count]=p;
  13. count++;
  14. }
  15.  
  16. public void displayAddressBook(){
  17.  
  18. for(int i=0;i<count;i++)
  19. entry[i].get();
  20. }
  21. }
  22.  
  23. class Person{
  24. protected String name,phone;
  25. protected Address addr;
  26. public Person(){
  27.  
  28. }
  29. public Person(String s1,String s2){
  30. this.name=s1;
  31. this.phone=s2;
  32. }
  33. public Person(String s1,String s2,Address a){
  34. this.name=s1;
  35. this.phone=s2;
  36. this.addr=a;
  37. }
  38. public void setName(String s){
  39. this.name=s;
  40. }
  41. public void setPhone(String s){
  42. this.phone=s;
  43. }
  44. public String getName(){
  45. return name;
  46. }
  47. public String getPhone(){
  48. return phone;
  49. }
  50.  
  51. public void get(){
  52. System.out.println("Name :"+this.getName());
  53. System.out.println("Phone :"+this.getPhone());
  54. }
  55. }
  56.  
  57. class Address{
  58. protected String street,city,state;
  59.  
  60. public Address(){
  61.  
  62. }
  63. public Address(String s1,String s2,String s3){
  64. this.street=s1;
  65. this.city=s2;
  66. this.state=s3;
  67. }
  68.  
  69. public String getFullAddress(){
  70. return this.street+'\n'+this.city+'\n'+this.state;
  71. }
  72. }
  73.  
  74. class BussinessAssociate extends Person{
  75. private String jobtitle,companyName;
  76.  
  77.  
  78. public BussinessAssociate(){}
  79. public BussinessAssociate(String s1,String s2,Address a,String s3,String s4){
  80. super(s1,s2,a);
  81. this.jobtitle=s3;
  82. this.companyName=s4;
  83.  
  84. }
  85. public String getJobTitle(){
  86. return jobtitle;
  87. }
  88. public String getCompanyName(){
  89. return companyName;
  90. }
  91. public void dispBusinessAssociates(){
  92. super.get();
  93. System.out.println("Job title :"+this.jobtitle);
  94. System.out.println("Company name :"+this.companyName);
  95. }
  96. public void get(){
  97. super.get();
  98. this.dispBusinessAssociates();
  99. }
  100. }
  101.  
  102. class PersonalFriend extends Person{
  103. private String message;
  104. public PersonalFriend(){
  105.  
  106. }
  107. public PersonalFriend(String s1,String s2,Address a,String s3){
  108. super(s1,s2,a);
  109. this.message=s3;
  110. }
  111. public String getMessage(){
  112. return message;
  113. }
  114.  
  115. public void disPersonalFriend(){
  116. super.get();
  117. System.out.println("Message :"+this.message);
  118. }
  119. public void get(){this.disPersonalFriend();}
  120. }
  121.  
  122. public class AddressBookApp{
  123. public static void main(String[] a){
  124. AddressBook book1=new AddressBook(10);
  125. Address ad1=new Address("No 2 Jalan Mawar","Skudai","Johor Bahru");
  126. Address ad2=new Address("202-2 Jalan Bendahara","Muar","Johor");
  127. Address ad3=new Address("111-3 Jalan Duku","Muar","Johor");
  128.  
  129. Person newfriend1 =new Person("Ms.X","555-1212",ad1);
  130. book1.addPerson(newfriend1);
  131.  
  132. BussinessAssociate b1;
  133. b1=new BussinessAssociate("Mr. Yeo","019-2342",ad2,"General Manager","Motorola");
  134. book1.addPerson(b1);
  135.  
  136. PersonalFriend f1=new PersonalFriend("Mrs. Zyda","012-8278",ad3,"My school mate");
  137. book1.addPerson(f1);
  138.  
  139. book1.displayAddressBook();
  140.  
  141.  
  142. }
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement