Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

6. Identify seven types of hidden histories.

Answered: 1 week ago

Question

What is the relationship between humans and nature?

Answered: 1 week ago