CS 307Assignment, Implementing a Program With
Multiple Classes - Mastermind
Official Assignment Handout
Programming Assignment 5: This is a pair assignment. You may work with one other person on this assignment using the pair programming technique. Review this paper on pair programming. You are not required to work in a pair on the assignment. If you begin working with one partner and do not wish to finish the assignment with that partner you must complete the assignment individually. If you work with a partner the intent is that work together, at the same computer, on the assignment. One person "drives" (does the typing and explains what they are doing) and the other person "navigates" (watches and asks questions when something is unclear). You should not partition the work, work on your own, and then put things together. You may not acquire, from any source (e.g., another student or student pair or an internet site), a partial or complete solution to a problem or project that has been assigned. You may not show another student or student pair your solution to an assignment. You may not have another person (current student, former student, tutor, friend, anyone) “walk you through” how to solve an assignment. Review the class policy on collaboration from the syllabus.
If you work with a partner you will turn in one version of your code. Pick which account to submit the code to.
If you are working with a partner and want to use slip days you must both have the required number of slip days and both students use slip days. If the assignment is turned in 1 day late each student in a pair must have at least 1 slip day and it costs each student in the pair 1 slip day.
The purpose of this assignment is to design and implement a program with multiple classes
Provided Files:
| File | Responsibility | |
| Sample output | SampleOutput.txt. A text file that shows what the output of the game could be. You do not have to follow this format exactly, but yours should be similar. | Provided by me. |
| Implementation | MastermindDriver.java | Provided by me. DO NOT ALTER. This is how we will run your game. |
| Implementation | Game.java | Provided by you and me. (Mostly you) |
| Implementation | Other classes you create for the game of Mastermind. | Provided by you. |
| Testing | TestSummary.txt. A document detailing the tests you ran on your classes and program to ensure they work correctly. point out the testing code in the classes. (Method names, purpose, results of tests.) | Provided by you |
| Submission | A5.jar. JAR of the program, including the source code for all classes you created plus TestSummary.txt, Game.java, and MastermindDriver.java. | Provided by you. |
Description:
Under the constraints of the General Assignment Requirements, design and implement a program to play a text based version of the board game Mastermind. You are free to use whatever classes and methods from the Java standard library you wish to use. Read the tips for this assignment at the bottom of the handout!
Read the Wikipedia article on the game of Mastermind.
The version of the game you implement will have the following properties.
The output of the game should be a simple text based display. Look at this page for sample output. (User responses are in bold italics.) Your program does not have to match this output exactly. You can make changes to the style of the output if you like.
Part of the assignment grade will be determined by how easily your program could be altered to allow a different number of pegs in the code and how easily different colors could be added, assuming they start with a different letter than other existing colors. (Up to 26, one for each capital letter. Are there any colors that start with an X?) For example how easily would it be to change the code to have 5 pegs and allow pegs to be the color Maroon?
Part of the assignment grade will be determined by if you broke the problem up into different classes. One of the criteria of the assignment is to break the problem up into multiple classes even if you think the problem could be solved more easily with ONE BIG CLASS. For this assignment you should err on the side of having lots of simple classes instead of a few complex ones.
The top level class of your program must be called Game. It must have a constructor
that takes a boolean. The boolean is used for
testing purpose. If it is true, then the secret code is revealed
throughout the game. The Game class must also have a method
named runGames that carries out the actual games. Your program must run correctly when
the main method of class Mastermind.java is called.
You must provide a description of the tests you ran. Even though your testing code will not be executed you must include your testing code in your submission (simply comment it out) and a file that describes your testing strategy.
When finished turn in a jar file named A5.jar that contains all the files needed for your program to be compiled and run. Include all the source code for all the classes you created, Game.java, MastermindDriver.java, and TestSummary.txt. (Don't turn in the .class files.) This is not an executable jar, simply an archive jar. Use the turnin program to turn the file in. jar is a program included in the standard edition of Java loaded on the computers in the Microlab and that you have on your computer if you downloaded Java. See Sun's page for using jar, my tips for using jar, and / or the guide to creating jars in Eclipse.
Ensure you jar the .java files not the .class files.
Checklist. Did you remember to:
chars,
Strings, ints, or
possibly use the built in Java Color class. For this
assignment you should err on the side of having lots of simple classes
instead of a few complex ones.import java.util.Scanner;
in the class that uses the Scanner class. To create a Scanner
object that is tied to the keyboard you could use the following code:Scanner s;
s = new Scanner(System.in);
In this assignment the only method you should need from the
Scanner class is the getLine() method. Here are some examples of using
the getLine() method.System.out.print("Enter your name: ");
String name = s.nextLine();
System.out.print("Press Enter to continue: ");
s.nextLine();
Code: RRRR
Guess: BBBBCode: RRRR
Guess: RBBYCode: RBYR
Guess: BBRGCode: R-YR
Guess: B-RGCode: --YR
Guess: B--GCode: RBYR
Guess: BBRG
generates a result of 1 black peg and 1 white peg.