Question: JAVA PROGRAMMING Mastermind is a game where the player tries to figure out a pattern based on a series of clues. 4 different colored pegs
JAVA PROGRAMMING
Mastermind is a game where the player tries to figure out a pattern based on a series of clues. 4 different colored pegs (R for red, B for blue, G for green, W for white, P for purple, and Y for yellow) are chosen and hidden from the player. Then the user picks 4 pegs and guesses at the pattern. The computer will tell the user how many pegs are the correct color (hint, hint you may want to reuse them in the next guess). The computer will also tell the user how many of the correctly colored pegs are also in the correct position. The user has up to 10 attempts to figure out the pattern
MastermindPuzzle class
All instance variables should be private (not public or protected)
Should be abstract
Needs to implement Winnable interface
Need at least the default constructor
getNumPieces needs to return an integer with the number of pegs in a puzzle (currently 4 use constants!)
chooseSolution should accept an integer that is the puzzle to choose and it must be abstract
startGame should accept an integer that is the puzzle to choose (1 through 3 or -1 for a random puzzle)
You must call chooseSolution in this method
I recommend that this method also reset your other variables that remember the state of the current game
makeGuess accepts a character array with the letters to check
I recommend that this method increase the number of guesses made, and set 2 instance variables that indicate the number of correctly colored pegs and the number in the correct position
This is the longest, most complicated method in the class
getLastCorrectColorCount needs to return the number of pegs that are the correct color in the last guess
getLastCorrectPositionCount needs to return the number of pegs that are in the correct position in the last guess
You may add extra methods to help yourself
EasyMastermindPuzzle class
This should be a subclass of MastermindPuzzle
This class ONLY needs constructor(s) and chooseSolutionchooseSolution should do the following:
If the parameter is 1, set the puzzle to R, G, B, W
If the parameter is 2, set the puzzle to P, R, W, Y
If the parameter is 3, set the puzzle to W, B, Y, P
If the parameter is -1, set the puzzle to random colors (4 out of R, G, B, W, Y, P)
HardMastermindPuzzle class
This should be a subclass of MastermindPuzzle
This class ONLY needs constructor(s) and chooseSolutionchooseSolution should do the following:
If the parameter is 1, set the puzzle to R, G, B, R
If the parameter is 2, set the puzzle to P, R, P, Y
If the parameter is 3, set the puzzle to W, W, Y, P
If the parameter is -1, set the puzzle to random colors (4 out of R, G, B, W, Y, P) with at least 1 duplicate color within in the puzzle
I already have the main. All it is is prompting the user for inputs using a loop and getting it to and from the other classes. I need help getting the other two classes together thank you very much
Heres what the output is expected to be:
Sample Run #1: (the highlighted text is what the user types)
1=easy, 2=hard? 1
Puzzle num? 1
Guess? R G B Y
3 3 --> R G B Y
Guess? R G B W
4 4 --> R G B W
Congratulations!
Sample Run #2: (the highlighted text is what the user types)
1=easy, 2=hard? 2
Puzzle num? 1
Guess? R Y B B
2 2 --> R Y B B
Guess? R R G R
3 2 --> R R G R
Guess? R G B R
4 4 --> R G B R
Congratulations!
Sample Run #3: (the highlighted text is what the user types)
1=easy, 2=hard? 1
Puzzle num? 1
Guess? P Y G B
2 0 --> P Y G B
Guess? R G B Y
3 3 --> R G B Y
Guess? G R P Y
2 0 --> G R P Y
Guess? B G R W
4 2 --> B G R W
Guess? B G R W
4 2 --> B G R W
Guess? B G R W
4 2 --> B G R W
Guess? B G R W
4 2 --> B G R W
Guess? B G R W
4 2 --> B G R W
Guess? B G R W
4 2 --> B G R W
Guess? B G R W
4 2 --> B G R W
Sorry, you lost
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
