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

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!