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

Add a getChoice() method to the Validation class: a. Signature of the class is:

ID: 3594392 • Letter: A

Question

Add a getChoice() method to the Validation class:

a. Signature of the class is: public static void getChoice(Scanner sc, String enterMsg, String vaildChoices)

b. Where the String parameter enterMsg is the user prompt - Ex: Continue (y/n): ?

c. Where the String parameter validChoices is a string that contains all of the valid letter choice answers for the prompt - Ex: YyNn

d. Use the String.contains() method to determine if the choice the user enters is valid: if(validChoices.contains(UserChoice)) isValid = true;


Explanation / Answer

import java.util.Scanner;
class Validation {
  
// method that makes isValid true if the entered value by user is valid
public void getChoice(Scanner sc, String enterMsg, String vaildChoices)
{
boolean isValid = false;
  
// taking user input
System.out.print(enterMsg);
String UserChoice = sc.next();
  
// using contains method
if(vaildChoices.contains(UserChoice)) isValid = true;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote