Homework 8

Due Thurs, Jan 13, 18:00


Exercise  (10 points)

Consider the TicTacToe class.  Compile and run the game. Most of the code is for setting up and maintaining the user interface and you don't need to look at it.  The playing board is represented by a 3x3 array of type String (the instance variable board).  At the start of a game, all of the elements are initialized to the empty string "" in the method initializeBoard.  When a player takes a turn, the appropriate element on the board is filled in with an "X" or an "O" (depending on whose turn it is), and the lookForWinner method is called.  If a winner is found, it is announced at the bottom of the user interface and the game ends.  Fill in the missing lookForWinner method that checks each row, column, and both diagonals for a winner, and returns "X", "O", or "" (if there is no winner).  Test your class by playing the game with a winner in each row, column and diagonal.


Submit the following files to Anne (javaiscl (at googlemail.com)):
TicTacToe.java