Extension 5.3: Tic-Tac-Toe¶
Introduction¶
The design of software can often be specified using its API, or Application Programming Interface. The API specifies the methods that are offered by the software. Documentation for those methods typically includes:
the signature of each method:
the method’s name
the types of the method’s parameters
the return type (or
void
) for the method
the documentation for the method
The above should be sufficient to use the software, but it can also form the design document for implementing the software.
Procedure¶
Find the assignment’s code in the
tictactoe
package of thenonexam
folder.Watch the documentation video.
Implement the methods according to the documentation.
Test as you go by running the unit test
TTTTest
found in thetictactoe.tests
package in thetest_src
folder.
It is suggested that you implement the methods in the following order:
String[][] genBoard() (actually shown in the video)
-
For this assignment, when an improper input is found by methods like this, you are required to
throw
an IllegalArgumentExceptionAn example of that is done for you in
verifyValidPlayer
, so take a look at that for guidance.
Note that when comparing to see if two strings are equivalent you should use the .equals()
method, NOT ==
, like
String s1 = "Hello!";
String s2 = "Hello!";
if(s1.equals(s2) == true) {
// This will be true! (the == would not!)
}
You can even reverse the order of the two strings, like:
if(s2.equals(s1) == true) { // s2 first here
// This will be true!
}
Other methods are in the class and documentation, but they are already implemented for you:
Play the game¶
Watch this video showing the play of the game.
Run the
Game
class in thetictactoe
package of yourextensions
folder to play against the computer.