Classes: Final version of Mastermind
At the end of this lab, you will have a complete mastermind game and have written your first completely object oriented program that uses two classes.
Learning Objective(s)
- Experience the development and use of multiple classes
- Finish the mastermind game
- End the semester programming on a good note.
Overview of the Program
Finish the mastermind game
Details
Part 1: Create the Row class
- The class should have two constants (NUMHOLES and NUMCOLORS) and one field variable which would be an integer array that will hold either the solution or a user's guess.
- There should be two constructors:
- First constructor has no arguments and generates a random guess for the array.
- The second constructor is sent an array with numbers (already inputted by the user) and creates a row from it. This constructor should handle two error conditions (the array being sent is too small or too large).
- There are no mutators because you can't change a guess or the solution, just create new ones.
- There is one standard accessor. It returns the color (an int) of a specific hole (an int).
- You should implement two standard helper methods: toString, equals
- Use the code from a previous lab to implement a method to return the number of colors in the guess (an argument) that are perfect
- Use the code from a previous lab to return an array of the count of the numbers of each of the colors in a guess (or solution)
- Use the code from a previous lab to return how many of the guesses are good (but not perfect).
Part 2: Create the MastermindGame class
- The main method should repeat playing a complete game until the user decides to quit.
- The method to play a game should be sent a scanner and continue to get guesses from the user until the user guesses the solution.
- It constructors a computer row (using random numbers)
- It uses another method to get an array of numbers from the user for a guess
- It uses that array to constructor a guess row
- It then determines how many where perfect and how many were good and reports that to the user
- It tracks the number of guesses
Sample dialogue
I have the solution. What is your guess?
1 1 1 1 1
On guess 1:
You got 0 perfect.
You got 0 good.
What is your next guess?
2 2 2 2 2
On guess 2:
You got 2 perfect.
You got 0 good.
What is your next guess?
2 2 3 3 3
On guess 3:
You got 0 perfect.
You got 2 good.
What is your next guess?
4 4 2 2 4
On guess 4:
You got 3 perfect.
You got 0 good.
What is your next guess?
4 0 2 2 0
On guess 5:
You got 3 perfect.
You got 2 good.
What is your next guess?
0 4 2 2 0
You guessed it.
Do you want to play again (y or n)? n
Submission
- create an empty zip folder
- place your java file into it
- create a pdf document that contains your Software Development Report for this program and place the pdf file into the zip folder
- submit the zip folder on canvas