---+ 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) 1 Experience the development and use of multiple classes 1 Finish the mastermind game 1 End the semester programming on a good note. ---++ Overview of the Program Finish the mastermind game ---++ Details ---+++Part 1: Create the <b>Row</b> class 1. 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. 1. There should be two constructors: a. First constructor has no arguments and generates a random guess for the array. a. 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). 1. There are no mutators because you can't change a guess or the solution, just create new ones. 1. There is one standard accessor. It returns the color (an int) of a specific hole (an int). 1. You should implement two standard helper methods: toString, equals 1. 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 1. 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) 1. Use the code from a previous lab to return how many of the guesses are good (but not perfect). ---+++Part 2: Create the <b>MastermindGame</b> class 1. The main method should repeat playing a complete game until the user decides to quit. 1. 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. a. It constructors a computer row (using random numbers) a. It uses another method to get an array of numbers from the user for a guess a. It uses that array to constructor a guess row a. It then determines how many where perfect and how many were good and reports that to the user a. It tracks the number of guesses ---++Sample dialogue <pre>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 </pre> ---++ Submission a. create an empty zip folder a. place your java file into it a. create a pdf document that contains your Software Development Report for this program and place the pdf file into the zip folder a. submit the zip folder on canvas
This topic: CenterForComputing
>
WebHome
>
Syllabi
>
CSC121SylS2023
>
CSC121S2023Lab12
Topic revision: r1 - 2023-03-30 - cathybareiss
Copyright © 2008-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki?
Send feedback