|CMPU 101 - Assignment 6||Due: by 11:59 PM on Friday, April 7th|
$Revision: 1.1 $
In this assignment, you will write methods to read TicTacToe boards from the keyboard, and examine them to determine whether or not either player has won.
Your task is to read a game board from the keyboard in the following format. Each row of the game board will be specified as a single token, which should be a string of length 3. The characters 'X', 'O', and '-' will be used to indicate an X, O, or blank square.
After reading in a game board, your program should evaluate it to determine whether X wins, O wins, or the game is a draw and no one wins.
You should use a two-dimensional array of ints to represent the game board. In your class, define named constants to define integer values that represent blank squares, squares containing X, and squares containing O. Recall that a named constant is a private static final variable, e.g.
private static final int PLAYER_X = 1;
would define the named constant PLAYER_X to represent the integer value 1. Each element in the game board array should contain one of these values (depending on whether the square represented by the element contains an X, an O, or is blank).
Here are several example transcripts showing what the program should look like when it runs. User input is shown in bold.
Please enter a game board --X OXO X-- X wins Please enter a game board OOX XOX XXO O wins Please enter a game board XXO OXX XOO Draw Please enter a game board OO- XXX --- X wins
Make sure you use a two-dimensional array of ints to represent the game board.
Use top-down design to design your program. The pseudo-code for the overall program should become the main method. Add other methods as needed. Each method's pseudo-code should appear in the method as comments. Make sure you choose meaningful names for variables and methods.
5% of your grade will be based on the quality of your design, and 5% will be based on the quality of your comments and variable/method names. The easier your program is to read and understand, the more credit you will receive.
All of your methods should be static. Do not use any static variables (other than named constants).
Before running your program, make sure you have compiled it. Also, make sure your source file is in the Home directory (/home/cs101).
Open a terminal window using the button that looks like this:
Assuming the class in which your program is defined is called TicTacToe, run the following command from the terminal window:
If you need to kill your program and return to the command prompt, type Control-C in the terminal window.
You may implement any of the following features for extra credit. Please add a comment at the top of your source file indicating which extra credit features you have implemented.
When your program compiles and run correctly, submit the Java source file using the CS 101 Submission Website. Make sure you submit the Java source file: the filename should end in ".java", not ".java~" or ".class".