MIT Java coding questions
Section 32.12 – CS 213: Advanced Programming in Java | zyBooks 1 of 2 https://learn.zybooks.com/zybook/ELACCS213FreedmanSpring2024/c… Students: Section 32.12 is a part of 1 assignment: Java Project – Authoring assistant Includes: zyLab Due: 05/25/2024, 11:59 PM PDT 32.12 LAB*: Program: Authoring assistant LAB ACTIVITY 32.12.1: LAB*: Program: Authoring assistant 0 / 20 Note: Creating multiple Scanner objects for the same input stream yields unexpected behavior. Thus, as good practice is to use a single Scanner object for reading input from System.in. That Scanner object can be passed as an argument to any methods that read input. (1) Prompt the user to enter a string of their choosing. Store the text in a string. Output the string. (1 pt) Ex: Enter a sample 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! 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! (2) Implement the printMenu() method to print the following command menu. (1 pt) Ex: MENU c – Number of non-whitespace characters w – Number of words f – Find text r – Replace all !’s s – Shorten spaces q – Quit (3) Implement the executeMenu() method that takes 3 parameters: a character representing the user’s choice, the user provided sample text, and a Scanner object. executeMenu() performs the menu options, according to the user’s choice, by calling the appropriate methods described below. (1 pt) (4) In the main() method, call printMenu() and prompt for the user’s choice of menu options for analyzing/editing the string. Each option is represented by a single character. If an invalid character is entered, continue to prompt for a valid choice. When a valid option is entered, execute the option by calling executeMenu(). Then, print the menu, and prompt for a new option. Continue until the user enters ‘q’. Hint: Implement Quit before implementing other options. (1 pt) Ex: MENU c – Number of non-whitespace characters w – Number of words f – Find text r – Replace all !’s s – Shorten spaces q – Quit Choose an option: (5) 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 executeMenu() method, and then output the returned value. (4 pts) Ex: Enter a sample 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! 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! MENU c – Number of non-whitespace characters w – Number of words f – Find text r – Replace all !’s s – Shorten spaces q – Quit Choose an option: c Number of non-whitespace characters: 181 (6) 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 executeMenu() method, and then output the returned value. (3 pts) Ex: Number of words: 35 (7) Implement the �ndText() method, which has two strings as parameters. The �rst 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 executeMenu() method, prompt the user for a word or phrase to be found. Then call �ndText() and output the returned value. (3 pts) Ex: Enter a word or phrase to be found: more “more” instances: 5 (8) 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 executeMenu() method, and then output the edited string. (3 pts) Ex. 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. (9) 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 executeMenu() method, and then output the edited string. (3 pt) Ex: 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! Submit for grading Coding trail of your work What is this? 4/20 S – 0 – – – Latest submission – 5:18 PM PDT on 04/20/24 Only show failing tests Total score: 0 / 20 Open submission’s code 1: Compare output 0/1 Compare output Input 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! q Your Output Expected output starts with Enter a sample text: 2. You entered: We’ll continue our quest 2. in space. ⏎ 3. 1. Enter a sample text: 1. 3. There w You entered: We’ll continue our quest in space. There w 4. Output is nearly correct, but whitespace differs. See highlights above. Special character legend 2: Unit test 0/1 Test printMenu(). Should output the menu options. 4/26/2024, 5:28 PM Section 32.12 – CS 213: Advanced Programming in Java | zyBooks 2 of 2 https://learn.zybooks.com/zybook/ELACCS213FreedmanSpring2024/c… 3: Unit test 0/1 Test executeMenu(‘w’, “This is a test.”, scnr). Should output “Number of words: 4″ 4: Compare output 0/1 Compare output Input 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! c q Your Output Expected output ends with 1. Enter a sample text: 2. You entered: We’ll continue our quest 2. in space. ⏎ 1. 3. Number of non-whitespace characters: 181 There 3. MENU 4. c – Number of non-whitespace characters 5. w – Number of words 6. f – Find text 7. r – Replace all !’s 8. s – Shorten spaces 9. q – Quit 10. ⏎ 11. Choose an option: 12. Output differs. See highlights above. Special character legend 5: Compare output 0/1 Compare output Input This is a w q test. Your Output Expected output ends with 1. Enter a sample text: 2. You entered: This is a test. 3. 1. Number of words: 4 2. ⏎ 3. MENU 4. c – Number of non-whitespace characters 5. w – Number of words 6. f – Find text 7. r – Replace all !’s 8. s – Shorten spaces 9. q – Quit 10. ⏎ 11. Choose an option: 12 Output differs. See highlights above. Special character legend 6: Compare output 0/1 Compare output Input I want some water. I had some water earlier, but now he has some water. f some water q Your Output Expected output ends with 1. Enter a sample text: 2. You entered: I want some water. I had 2. some”some waterwater” earlieinstances: 3 1. 3. Enter a word or phrase to be found: 3. ⏎ 4. MENU 5. c – Number of non-whitespace characters 6. w – Number of words 7. f – Find text 8. r – Replace all !’s 9. s – Shorten spaces 10. q – Quit 11. ⏎ 12. Choose an option: Output differs. See highlights above. Special character legend 7: Compare output 0/1 Compare output Input I have a test! I am not prepared! r q Your Output Expected output ends with 1. Enter a sample text: 2. You entered: I have a test ! I am not prepared 1. 3. Edited text: I have a test . I am not prepared 2. ⏎ 3. MENU 4. c – Number of non-whitespace characters 5. w – Number of words 6. f – Find text 7. r – Replace all !’s 8. s – Shorten spaces 9. q – Quit 10. ⏎ 11 Choose an option: Output differs. See highlights above. Special character legend 8: Compare output 0/1 Compare output Input Testing that menu is called and can quit. q Your Output Expected output 1. Enter a sample text: 1. Enter a sample text: 2. ⏎ can quit. You entered: Testing that menu is called 2. and 3. 3. You entered: Testing that menu is called and can quit. 4. ⏎ 5. MENU 6. c – Number of non-whitespace characters 7. w – Number of words 8. f – Find text 9. r – Replace all !’s 10. s – Shorten spaces 11. q – Quit 12. ⏎ Output differs. See highlights above. Special character legend 9: Compare output 0/1 Compare output There are Input too many spaces here. Why? s q Your Output Expected output ends with 1. Enter a sample text: 2. You entered: There are 3. 1. Edited text: 2. ⏎ 3. MENU 4. c – Number of non-whitespace characters There are too many spaces here. Why? too 5. w – Number of words 6. f – Find text 7. r – Replace all !’s 8. s – Shorten spaces 9. q – Quit 10. ⏎ 11. Choose an option: Output differs. See highlights above. Special character legend 10: Unit test 0 / 11 Tests getNumOfNonWSCharacters(), getNumOfNonWSCharacters(), getNumOfWords(), �ndText(), replaceExclamation(), shortenSpace() symbol: method findText(String,String) location: variable studentMain of type AuthoringAssistant /usercode/zyLabsUnitTest.java:87: error: cannot find symbol studentString = studentMain.replaceExclamation(userString); ^ symbol: method replaceExclamation(String) location: variable studentMain of type AuthoringAssistant /usercode/zyLabsUnitTest.java:106: error: cannot find symbol studentString = studentMain.shortenSpace(userString); ^ symbol: method shortenSpace(String) location: variable studentMain of type AuthoringAssistant 6 errors How was this section? | Provide section feedback Activity summary for assignment: Java Project – Authoring assistant0 / 20 points Due: 05/25/2024, 11:59 PM PDT 0 / 20 points submitted to canvas Completion details 4/26/2024, 5:28 PM
Collepals.com Plagiarism Free Papers
Are you looking for custom essay writing service or even dissertation writing services? Just request for our write my paper service, and we'll match you with the best essay writer in your subject! With an exceptional team of professional academic experts in a wide range of subjects, we can guarantee you an unrivaled quality of custom-written papers.
Get ZERO PLAGIARISM, HUMAN WRITTEN ESSAYS
Why Hire Collepals.com writers to do your paper?
Quality- We are experienced and have access to ample research materials.
We write plagiarism Free Content
Confidential- We never share or sell your personal information to third parties.
Support-Chat with us today! We are always waiting to answer all your questions.