Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.00 KB | None | 0 0
  1. 8.11 LAB*: Program: Authoring assistant
  2. (1) Prompt the user to enter a string of their choosing. Store the text in a string. Output the string. (1 pt)
  3.  
  4. Ex:
  5.  
  6. Enter a sample text:
  7. We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. Nothing ends here; our hopes and our journeys continue!
  8.  
  9. You entered: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. Nothing ends here; our hopes and our journeys continue!
  10.  
  11. (2) Implement a printMenu() method, which outputs a menu of user options for analyzing/editing the string, and returns the user's entered menu option. Each option is represented by a single character.
  12.  
  13. If an invalid character is entered, continue to prompt for a valid choice. Hint: Implement Quit before implementing other options. Call printMenu() in the main() method. Continue to call printMenu() until the user enters q to Quit. (3 pts)
  14.  
  15. Ex:
  16.  
  17. MENU
  18. c - Number of non-whitespace characters
  19. w - Number of words
  20. f - Find text
  21. r - Replace all !'s
  22. s - Shorten spaces
  23. q - Quit
  24.  
  25. Choose an option:
  26.  
  27. (3) Implement the getNumOfNonWSCharacters() method. getNumOfNonWSCharacters() has a string as a parameter and returns the number of characters in the string, excluding all whitespace. Call getNumOfNonWSCharacters() in the main() method. (4 pts)
  28.  
  29. Ex:
  30.  
  31. Enter a sample text:
  32. We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. Nothing ends here; our hopes and our journeys continue!
  33.  
  34. You entered: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. Nothing ends here; our hopes and our journeys continue!
  35.  
  36. MENU
  37. c - Number of non-whitespace characters
  38. w - Number of words
  39. f - Find text
  40. r - Replace all !'s
  41. s - Shorten spaces
  42. q - Quit
  43.  
  44. Choose an option:
  45. c
  46. Number of non-whitespace characters: 181
  47.  
  48. (4) Implement the getNumOfWords() method. getNumOfWords() has a string as a parameter and returns the number of words in the string. Hint: Words end when a space is reached except for the last word in a sentence. Call getNumOfWords() in the main() method. (3 pts)
  49.  
  50. Ex:
  51.  
  52. Number of words: 35
  53.  
  54. (5) Implement the findText() method, which has two strings as parameters. The first parameter is the text to be found in the user provided sample text, and the second parameter is the user provided sample text. The method returns the number of instances a word or phrase is found in the string. In the main() method, prompt the user for a word or phrase to be found and then call findText() in the main() method. (3 pts)
  55.  
  56. Ex:
  57.  
  58. Enter a word or phrase to be found:
  59. more
  60. "more" instances: 5
  61.  
  62. (6) Implement the replaceExclamation() method. replaceExclamation() has a string parameter and returns a string which replaces each '!' character in the string with a '.' character. replaceExclamation() DOES NOT output the string. Call replaceExclamation() in the main() method, and then output the edited string. (3 pts)
  63.  
  64. Ex.
  65.  
  66. Edited text: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. Nothing ends here; our hopes and our journeys continue.
  67.  
  68. (7) Implement the shortenSpace() method. shortenSpace() has a string parameter and returns a string that replaces all sequences of 2 or more spaces with a single space. shortenSpace() DOES NOT output the string. Call shortenSpace() in the main() method, and then output the edited string. (3 pt)
  69.  
  70. Ex:
  71.  
  72. Edited text: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. Nothing ends here; our hopes and our journeys continue!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement