Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

ZY Labs Program: Authoring assistant (Java) (1) Prompt the user to enter a strin

ID: 3573330 • Letter: Z

Question

ZY Labs Program: Authoring assistant (Java)

(1) Prompt the user to enter a string of their choosing. Store the text in a string. Output the string.

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 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. 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.

Ex:

(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.

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!

(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.

Ex:

(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.

Ex:

(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.

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.

(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.

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!

Provided Code

import java.util.Scanner;

public class AuthoringAssistant {

   public static void main(String[] args) {
      /* Type your code here. */
    
      return;
   }
}

Explanation / Answer

Class Name is AuthoringAssistant.java

import java.util.Scanner;
public class AuthoringAssistant {
   static int c=0;
   static void printMenu(){
       System.out.println("Menu");
       System.out.println("w - Number of words");
       System.out.println("f - find text");
       System.out.println("r - replace all !'s");
       System.out.println("s - shorten spaces");
       System.out.println("q - quit");  
   }
   public void getNumOfNonWSCharacters(){
       }
   static void getNumOfWords(String s){
       System.out.println("Number of Words "+s.length());
   }
   public static int findText(String m,String t){
       int count=0;
       if (m.contains(t)) {
   int withSentenceLength = m.length();
   int withoutSentenceLength = m.replace(t, "").length();
   count = (withSentenceLength - withoutSentenceLength) / t.length();
  
   }
       System.out.println("Word is "+t+" Matches to this word "+count);
   return count;
      
   }
   public static String replaceExclamation(String rs){
       String newString = rs.replaceAll("!", ".");
       System.out.println("New String Without ! "+newString);
       return newString;
      
   }
   public static String shortenSpace(String Shortst){
       String newShort = Shortst.replaceAll("\s{2,}", " ").trim();
       System.out.println(newShort);
       return newShort;
   }
   public static void main(String[] args) {
       System.out.println("Enter your string");
       Scanner as = new Scanner(System.in);
       String userst = as.nextLine();
       System.out.println("Your string is " +userst);
      
       printMenu();
      
       char option;
       Scanner op = new Scanner (System.in);
       System.out.println ( "Enter Option");
       option = op.next().charAt(0);
      
       switch ( Character.toUpperCase(option) ) {
   case 'W':
       getNumOfWords(userst);
   break;
   case 'F':
       System.out.println("Enter your word to Find in String");
               Scanner tw = new Scanner(System.in);
               String targetWord = tw.nextLine();
               findText(userst, targetWord);
   break;
   case 'R':
       replaceExclamation(userst);
       break;
   case 'S':
       shortenSpace(userst);
       break;
   case 'Q':
       break;
   default:
   System.err.println ( "Invalid Option" );
   break;
   }
              
   }

}

Thank You..!