1. Member
Join Date
Nov 2011
Posts
5
Rep Power
0

## URGENT!!! assignment (Mastermind)

We will write a version of MasterMind, which has two hints for a code breaker to break a secret code:
• the number of position (and digit) matches; and
• the number of remaining digit matches. The positions of these digits do not match.
In the process of determining the hints, each digit can be used once only. We need to ignore (or
remove) matched digits from the secret code and the guessed code before further checking. For
example, if the secret code is 0022 and the guessed code is 0241. The hint is "1 position match and 1
digit match". The digit with matched position is the first "0" (secret code becomes -022 and guessed
code becomes -241, where "-" represents an ignored digit) and the remaining digit match is "2" (secret
code now becomes -0-2 and guessed code becomes --41). If the guessed code is 2021 instead, the hint
is "2 position matches and 1 digit match" with the middle "02" as the matched positions and the digit
"2" as the matched digit.

(i) Create a class MasterMind with an integer array secretCode of size 4 (which may be changed
to other values) which stores the secret digits starting from the left. For example, if the secret
integer is 0232, secretCode stores the digits 0, 2, 3 and 2 in its elements 0, 1, 2 and 3
respectively. The class has another attribute guessCount to keep track of the current guess count
which is initialized to zero. Copy the content of the class as the answers to this part.

(ii) Write a constructor of MasterMind which initializes secretCode randomly in which the
maximum value of each digit is specified by the parameter maxInteger of the constructor. Store
the value of the parameter maxInteger in another attribute maxInteger. Also write a method
printSecretCode() which prints the secret code to the console in a line. Copy the content of
the constructor/method as the answers to this part.

(iii) Write a driver class TestMasterMind with a main() method which creates a MasterMind
object whose maximum value of each digit is 4 and print the secret code to the console. Copy the
content of the class as the answers to this part.

(iv) Write a method oneGuess(int guess) of the class MasterMind which increases guessCount
by 1 and returns the number of correct position(s) and digit(s) in element 0 and 1 of an array hint
respectively. Here you need to first extract the digits from the integer guess and then compare
them with secretCode. The procedure of extracting digits from an integer can be found on p.106
of Unit 4. In this part, the number of correct digit(s) (i.e., hint[1]) should always be zero since it
is more difficult to do and will be done in another part. You can test your method to make sure
hint[0] is correctly returned. Copy the content of the method as the answers to this part.

(v) Write a method play() of the class MasterMind to display the dialog box asking the player to
enter an integer with digits in the range 0 to maxInteger, display the appropriate message after
checking the guess using oneGuess() and repeat the guessing process until the guess is correct.
(Actually the program can be terminated with an error if the user click "Cancel" instead of "OK".)
The game can actually be played now despite the hint on correct digits is not given. Add a
statement in TestMasterMind calling the method play() to play the game. Copy the content of
the method as the answer to this part.

(vi) This part is difficult and you need to think carefully how to do it. Write a method findHint1() of
the class MasterMind with any appropriate parameters to find and return hint[1] to the calling
method, which is oneGuess(). Also, update oneGuess() so that the correct value of hint[1]
(instead of zero) is also returned. Copy the content of the method and changes in oneGuess() as

2. ## Re: URGENT!!! assignment (Mastermind)

Start by outlining your projects requirements, the goals and create logical steps to get there. What classes do you need? What are your variables going to look like?

Also, writing URGENT!!!!!!! in your post title will not get you any faster of a response. In fact it may cause people to respond slower because it can be viewed as an insult to other peoples times. This also goes for posting your deadlines too.

If you have more direct questions and not "Please do this for me" questions, please be more specific. Your instructions tell you what has to be done, so start working on something.

3. ## Re: URGENT!!! assignment (Mastermind)

Moderator advice: This forum is for technical discussion, and many members here will be willing to help you with a specific problem. It is not however a place where your homework will be done for you to allow you to cheat your way through a passing grade.

If you have a specific question (see How to ask questions the smart way) feel free to start a new thread. I'm locking this homework dump.

db

4. ## Re: URGENT!!! assignment (Mastermind)

Given this and your previous question, it seems you're quite lost in this class. I suggest that you arrange a conference with your instructor as soon as possible as this offers your best hope of catching up. Either that or dropping the class.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•