Question
Help writing this code? Here is the method isValidCode which may be helpful. public static boolean isValidCode( int numPositions, char [] symbols, char [] code)
Help writing this code?
Here is the method isValidCode which may be helpful.
public static boolean isValidCode( int numPositions, char [] symbols, char [] code) {
if (numPositions == code.length) {
for (int i = 0; i < code.length; i++) {
if (indexOf(symbols, code[i]) == -1 ) {
return false;
}
}
return true;
}
return false; //TODO replace
}
/**
* Prompts the user for a string value by displaying prompt.
* Note: This method should not add a new line to the output of prompt.
*
* After prompting the user, the method will read an entire line of input and remove
* leading and trailing whitespace. If the line equals the single character '?'
* then return null. If the line is a valid code (determine with isValidCode) return
* the code, otherwise print "Invalid code." and prompt again.
*
* @param input The Scanner instance to read from System.in
* @param prompt The user prompt.
* @param numPositions The number of code positions.
* @param symbols The valid symbols.
* @return Returns null or a valid code.
*/
public static char[] promptForGuess(Scanner input, String prompt, int numPositions, char[] symbols) {
return null; //TODO replace
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started