Advertisement
Guest User

Untitled

a guest
Mar 27th, 2018
413
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.50 KB | None | 0 0
  1. Today's Activities
  2. Prliminaries
  3. Create an L10 project with a program named l10.AddressBook. Download the files AddressBook.java and Contact.java into the l10 package.
  4. Open the data type class Contact and examine the code. It's a standard data-type class. It has instance variables, a constructor, getters, setters, and a toString method. There's nothing unusual about it.
  5.  
  6. Open the program AddressBook, examine the code, then run the program. Enter a zero when it asks how many contacts you have:
  7.  
  8. Simple Contact List
  9. -------------------
  10.  
  11. This program reads in your contacts, then lets you search them.
  12.  
  13.  
  14. How many contacts do you have? 0<CR>
  15.  
  16. For each contact, enter their name.
  17. Optionally add a phone or email.
  18.  
  19. Your Contacts Are:
  20.  
  21.  
  22. Search your contacts.
  23. Leave the name blank to quit.
  24.  
  25. Enter a name to search for: Young<CR>
  26.  
  27. Enter another name (or leave blank to quit): Bob<CR>
  28.  
  29. Enter another name (or leave blank to quit): e<CR>
  30.  
  31. Enter another name (or leave blank to quit): x<CR>
  32.  
  33. Enter another name (or leave blank to quit): <CR>
  34. We are going to make this program do some work.
  35.  
  36. All the code you need to write is going to be in the program. Leave the data type class unchanged.
  37.  
  38. Programming Activity 1
  39. First we're going to update the readContacts method so that it actually reads in the contacts. It will prompt the user for the name, phone and email of the contact. The user must enter a name, but may leave the phone and email fields blank. For example:
  40. Simple Contact List
  41. -------------------
  42.  
  43. This program reads in your contacts, then lets you search them.
  44.  
  45.  
  46. How many contacts do you have? 5<CR>
  47.  
  48. For each contact, enter their name.
  49. Optionally add a phone or email.
  50.  
  51. Enter a contact's name: Mark Young<CR>
  52. Enter the contact's phone number (optional): 902-496-8153<CR>
  53. Enter the contact's e-mail address (optional): myoung@cs.smu.ca<CR>
  54.  
  55. Enter a contact's name: <CR>
  56. You can't have a blank name!
  57. Enter a contact's name: David Young<CR>
  58. Enter the contact's phone number (optional): 902-555-1234<CR>
  59. Enter the contact's e-mail address (optional): <CR>
  60.  
  61. Enter a contact's name: <CR>
  62. You can't have a blank name!
  63. Enter a contact's name: Robert Young<CR>
  64. Enter the contact's phone number (optional): 902-555-2345<CR>
  65. Enter the contact's e-mail address (optional): <CR>
  66.  
  67. Enter a contact's name: Andrew Deputter<CR>
  68. Enter the contact's phone number (optional): <CR>
  69. Enter the contact's e-mail address (optional): andrew.deputter@nosuch.com<CR>
  70.  
  71. Enter a contact's name: Bob McKenzie<CR>
  72. Enter the contact's phone number (optional): <CR>
  73. Enter the contact's e-mail address (optional): <CR>
  74.  
  75. Your Contacts Are:
  76.  
  77.  
  78. Search your contacts.
  79. Leave the name blank to quit.
  80.  
  81. Enter a name to search for: Young<CR>
  82.  
  83. Enter another name (or leave blank to quit): <CR>
  84. Note that the program doesn't actually print out the contacts, or show you the people you searched for. Those parts come up in the other activities.
  85.  
  86. Programming Activity 2
  87. Complete the implementation of the method printContacts. It merely prints out each element of the array it's given, one per line.
  88. Keep in mind that our Contact class has a toString method.
  89. After entering the data shown in the example above, you should see the following output for your contacts:
  90.  
  91. Your Contacts Are:
  92. Mark Young // 902-496-8153 // myoung@cs.smu.ca
  93. David Young // 902-555-1234 //
  94. Robert Young // 902-555-2345 //
  95. Andrew Deputter // // andrew.deputter@nosuch.com
  96. Bob McKenzie // //
  97. Next we'll get that search working.
  98.  
  99. Programming Activity 3
  100. Complete the implementation of the method searchContacts. It is already set up to keep reading search terms (partial names) until the user leaves it blank. What it needs to do is take the search term the user entered and search thru the array for contacts with that search term as part of their name. Every matching contact gets printed.
  101. Note that the method you need is called contains. You need to ask each contact's name wheter it contains the search term.
  102.  
  103. Just ask the name. Don't look for the search term in the phone number or e-mail address.
  104. When you're done, you should be able to execute the searches:
  105.  
  106. Enter a name to search for: Young<CR>
  107. Mark Young // 902-496-8153 // myoung@cs.smu.ca
  108. David Young // 902-555-1234 //
  109. Robert Young // 902-555-2345 //
  110.  
  111. Enter another name (or leave blank to quit): Bob<CR>
  112. Bob McKenzie // //
  113.  
  114. Enter another name (or leave blank to quit): e<CR>
  115. Robert Young // 902-555-2345 //
  116. Andrew Deputter // // andrew.deputter@nosuch.com
  117. Bob McKenzie // //
  118.  
  119. Enter another name (or leave blank to quit): x<CR>
  120.  
  121. Enter another name (or leave blank to quit): n<CR>
  122. Mark Young // 902-496-8153 // myoung@cs.smu.ca
  123. David Young // 902-555-1234 //
  124. Robert Young // 902-555-2345 //
  125. Andrew Deputter // // andrew.deputter@nosuch.com
  126. Bob McKenzie // //
  127.  
  128. Enter another name (or leave blank to quit): <CR>
  129. Submit the program class. You will be graded on the following:
  130.  
  131. readContacts prompts for and reads a name
  132. ... readContacts rejects empty names
  133. ... using the read-test-process-read idiom
  134. ... readContacts reads phone and email
  135. ... readContacts creates a Contact with the given information
  136. ... and places it properly in the array
  137. printContacts prints every element of the array it was given
  138. ... without doing more work than is necessary
  139. searchContacts visits every element of the array
  140. ... names that contain the search term are printed
  141. ... names that don't contain the search term are not printed
  142. ... no useless code included
  143. ... loop for reading search terms has not been broken
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement