Review arrays: Mastermind part 1
Learning Objective(s)
- Improving programming and working with arrays
Overview of the program
- The user inputs an array of colors (represented by integers) and the program generates an array of colors.
- The system outputs how many of the colors in the two arrays are perfect matches (i.e. the same color in the same position).
- The system then outputs the number of each of the colors in each of the arrays.
- These are tools that will help create a master mind game program.
Details
- The keyboard should only be instantiated one time in the running of the program.
- You must implement at least 4 different colors.
- The first color should be white and the last color should be black.
- Use constants for all colors, the number of "spots" in the game, the first color, and the last color.
- Have a method that returns a string for a given color (int).
- Have a method that displays the "menu". It should use the constants. It is best if it uses a loop (but that is not necessary)
- Have a method that return a valid color. It should continue to get a value until the user inputs a valid color.
- Have a method that returns an array of colors inputted by the user. It should be sent the number of spots
- Have a method that returns an array of random colors. It should be sent the number of spots.
- Have a method that returns the number of colors that are an exact match in the two arrays
- Have a method the returns the number of times a value appears in the array.
- Program should be called MasterMind1
Sample dialogue
Color choices are:
0) white
1) red
2) blue
3) green
4) yellow
5) black
What color do you want? 0
What color do you want? 5
What color do you want? -1
Invalid choice. Try again.
Color choices are:
0) white
1) red
2) blue
3) green
4) yellow
2
What color do you want? 7
Invalid choice. Try again.
Color choices are:
0) white
1) red
2) blue
3) green
4) yellow
5) black
3
What color do you want? 3
There are 2 white in the random list
There are 1 red in the random list
There are 1 blue in the random list
There are 0 green in the random list
There are 1 yellow in the random list
There are 0 black in the random list
There are 1 white in the user list
There are 0 red in the user list
There are 1 blue in the user list
There are 2 green in the user list
There are 0 yellow in the user list
There are 1 black in the user list
There are 1 perfect matches between the two lists.
Submission
- Create your SDR.
- In Lessons Learned, insights about coding and arrays where you have improved your understanding
- If you used any hints, be sure to indicate that in the Outside Resources Used section
- For Future Improvements include a discussion about ideas how to not waste as much space.
- Convert your SDR into a pdf document
- Create an empty zip folder
- Place your java file and pdf document in it.
- Submit the zip folder on canvas
Hints
No hints this time. Just work on the methods (in order listed above) without moving until that method compiles, is tested, and works
Optional improvements
None this time.