-5

This code is supposed to be able to read a users input and do any of the options in the menu choice, What Im I missing? Sample outputs are

Enter a sample text: We'll continue our quest in space.

You entered: We'll continue our quest in space. 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: 6

   import java.util.Scanner

    public class AuthoringAssistant {
    public static void main(String [] args) { 
    Scanner scnr = new Scanner(System.in);
    String mainString = "";

    System.out.println("Enter a sample text:");
    mainString = scnr.nextLine();


    System.out.print("You entered: ");
    System.out.println(mainString);

    return mainString;
  }

  public static void printMenu(){

      Scanner scnr = new Scanner(System.in);

      char menuChoice = '?';

      String inputString="";

      while(menuChoice != 'q'){
        System.out.println("MENU");
        System.out.println("c - Number of non-whitespace characters");
        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");

        menuChoice = scnr.next().charAt(0);


        if(menuChoice == 'c'){
            getNumOfNonWSCharacters();


        }else if(menuChoice == 'w'){
            getNumOfWords();

        }else if(menuChoice == 'f'){
            findText();

        }else if(menuChoice == 'r'){
            replaceExclamation();

        }else if(menuChoice == 's'){
            shortenSpace();
        }
      }
  return;
  }

}
Albert
  • 1
  • 1

2 Answers2

0

You never called the method printMenu() in the main... so it can't do much than

Enter a sample text: We'll continue our quest in space.
You entered: We'll continue our quest in space. 

Just add the line

public static void main(String [] args) { 
    ...
    printMenu();
}

But you should share the Scanner instead of instanciate two.

And remove the return mainString; in the main, this is a void method.

AxelH
  • 14,325
  • 2
  • 25
  • 55
0

like @AxelH stated in a comment, you are missing a call to the printMenu() function. which means that that part of code will never be executed by your program.

FrankK
  • 482
  • 8
  • 23
  • Sorry, I beat you, I've write the answer based on my comment. There is nothing more to said here so I thought this was enough for an answer too ;) – AxelH Oct 13 '17 at 07:29