Question: (JAVA) Add a static method to the UserWrangler class called getMonthName which requires no arguments prompts the user for the name of a month until

(JAVA)

Add a static method to the UserWrangler class called getMonthName which

  • requires no arguments
  • prompts the user for the name of a month until the user enters a valid month name (use a loop)
  • returns the valid month name entered by the user (as a String)

/* The UserWrangler class will define methods to facilitate console interactions with the user (prompting, interpreting responses, validating responses...). */ import java.util.Scanner; class UserWrangler { final static String YES_RESPONSE = "yes"; final static String NO_RESPONSE = "no"; final static Scanner keyboard = new Scanner( System.in ); static boolean getYesNoResponse(String prompt) { String userResponse; // repeatedly ask the user for a response (and tell them what their options are) // until that idiot figures out how to type "yes" or "no" ;) do { System.out.println(prompt + " (" + YES_RESPONSE + " / " + NO_RESPONSE + ")"); userResponse = keyboard.next(); } while ( !(userResponse.equals(YES_RESPONSE) || userResponse.equals(NO_RESPONSE)) ); return userResponse.equals(YES_RESPONSE); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!