Question: Write a complete program that asks the user for a series of names. Your program then displays the longest name. Your program must validate the
Write a complete program that asks the user for a series of names. Your program then displays the longest name. Your program must validate the name. A name can only have letters a-z, A-Z and only one space. Prompt the user for a valid name, as long as the name is not valid your program must prompt the user. Your output must match the provided output. Here is the list of the methiods: public static void main(String[] args) { Scanner kb = new Scanner(System.in); run(kb); } public static void run(Scanner kb): this method should call all the other methods to start the program. There should be a while loop in this method allowing the user to keep running the program as long as the user is interested. public static String getYesOrNo(Scanner kb, String prompt): this method displays the prompt that is the parameter on the screen. The content of the prompt should be: Enter yes or no. As long as the user does not enter the yes or no, keep prompting the user. A while loop is needed. Once the user enters a valid answer, return it. public static void longestName(Scanner kb): this method should call the method getValidName to get a valid name from the user. This method should contain a while loop. In this method we need to call the method getValidName once before the while loop to get the first name. Then in the while loop the method getValidName must be called again. This method keeps asking the user do you have another name by calling the method getYesOrNo(). This method should determine the longest name out of the names. How do you determine the longest name? Also this method needs to determine if there is any tie. How? public static void description(): this method displays a description of the program public static String getValidName(Scanner kb): this method prompts the user to get a valid name. as long as the name is not valid, this method prompts the user. A while loop is needed here. Remember a valid name has only letters a-z, A-Z and only one space. Requirements: Comments Proper naming Indentation Output Required methods. Here is a sample output: This program asks for a series of names and and displays the longest name entered by the user. If two names are with the same length, a message will be printed.Enter a valid name containing only letters a-z ,A-Z and only one space. Enter a valid name--> Abraham Lincoln Name you entered: Abraham Lincoln Enter a valid name--> Marilyn Monroe Name you entered: Marilyn Monroe Do you have another name yes/no :ysds Do you have another name yes/no : yes Enter a valid name--> Mother Teresa Name you entered: Mother Teresa Do you have another name yes/no :yes Enter a valid name--> Nelson Mandela Name you entered: Nelson Mandela Do you have another name yes/no :yes Enter a valid name--> 34 erer Enter a valid name--> ert ert rt t Enter a valid name--> winstonn churchill Enter a valid name--> winstonn churchill Name you entered: winstonn churchill Do you have another name yes/no :no Winstonn churchill's name is longest (There was a tie!) Do you want to play again? Yes This program asks for a series of names and and displays the longest name entered by the user. If two names are with the same length, a message will be printed.Enter a valid name containing only letters a-z ,A-Z and only one space. Enter a valid name--> Donald Trump Name you entered: Donald Trump Enter a valid name--> Christopher Columbus Name you entered: Christopher Columbus Do you have another name yes/no :yes Enter a valid name--> Elvis presley Enter a valid name--> Elvis presley Name you entered: Elvis presley Do you have another name yes/no :Paul McCartney Do you have another name yes/no : yes Enter a valid name--> Albert Einstein Enter a valid name--> Albert Einstein Name you entered: Albert Einstein Do you have another name yes/no :no Christopher columbus's name is longest Do you want to play again? no ----jGRASP: operation complete
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
