Programming

As instructed by jim, I am reposting my question with work done so far... In this lab, you will demonstrate your understanding of two-dimensional arrays by implementing a TicTacToe game. The service class created in this lab will be utilized later in the semester as we move into subclasses and inheritance. Service Class TicTacToe Develop a TicTacToe class that manages a TicTacToe game. The class should define a two-dimensional array of characters named board. Two constructors are defined. The default constructor should set the player names to "Player 1" and "Player 2", set markers for the two players to 'X' and 'O', note that player1 goes first, and set the game board to its initial state. The overloaded constructor should accept player names and their selected character markers. The first player listed goes first. The game should also track the number of valid plays to determine when a tie has occurred (only 9 squares can be marked.) The initial game state marks each square (element of the array) with an indicator that the player can use to identify the square. For example, the squares below have the characters '1' through '9' stored in the array: 1 2 3 4 5 6 7 8 9 Although the array stores characters, the player will be able to enter an integer value to select a square. For example, a value of 1 will allow a player to select the upper left square. When the player using an 'X' marker has select square 1, the game board will store: X 2 3 4 5 6 7 8 9 In addition to accessor and mutator methods, the class should define methods to switch from player 1's control to player 2 (and vice versa), place a marker on the board, determine whether there is a winner or tied game, and construct strings containing the rules of the game, user prompts, and the display of the game board. For methods that return a boolean, the value indicates whether the action was successful or not. There should be no I/O in this class; Strings are composed and returned to the caller (client application). It is the caller's responsibility to display the returned String. Class UML diagram (constructors, accessor, and mutator methods not listed): TicTacToe - board : char[][] - player1 : String - player2 : String - currentPlayer : int - marker1 : char - marker2 : char - plays : int + switchPlayers( ) + placeMarker(int) : boolean + tie( ) : boolean + winner( ) : boolean + getRules( ) : String + getPrompt( ) : String + drawBoard() : String Client Application: Demonstrate the TicTacToe class in an application that allows users to play the game of TicTacToe. Players will play by alternating the use of a single keyboard. The application should display a welcome message and query for any set up information needed. Display of the game board is helpful as the game progresses. A sample run of the client application is below: Sample run of the application: Welcome! Tic Tac Toe is a two player game. Enter player one's name: Trish Enter player two's name: Pat Players take turns marking a square. Only squares not already marked can be picked. Once a player has marked three squares in a row, they win! If all squares are marked and no three squares are the same, a tied game is declared. Have Fun! Game Board 1|2|3 4|5|6 7|8|9 It is Trish's turn. Pick a square: 1 Game Board X|2|3 4|5|6 7|8|9 It is Pat's turn. Pick a square: 2 Game Board X|O|3 4|5|6 7|8|9 It is Trish's turn. Pick a square: 1 Square can not be selected. Retry Game Board X|O|3 4|5|6 7|8|9 It is Trish's turn. Pick a square: 4 ... game continues until finally Game Board X|O|X X|O|O 7|X|O It is Trish's turn. Pick a square: 7 Game Over - Trish WINS!!! Game Board X|O|X X|O|O X|X|O NOTES: 1.You will be developing TWO classes: the TicTacToe class and the Client class. The Client class contains the main method and should be named Lab2. 2.There should be no I/O performed in the TicTacToe class. All interaction with the end user should be done in the Client class. However, you will use methods of the TicTacToe class to generate the text. For example, when the client creates an instance of the TicTacToe class named myGame, the game prompt can be displayed from the client application to the end-user using: System.out.print(myGame.getPrompt()); 3.All prompts and display formats are up to you; the exact text in the above sample run is not required. 4.You may use any method for indicating a square. Just be sure the players understand how to pick a square. 5.Do not allow a player to select a square already marked. The player does not lose a turn when an illegal square is selected. 6.You may define additional methods in the TicTacToe class as needed, but you really shouldn't need any. 7.Warning: You must use the TicTacToe data members and method signatures listed in the UML diagram. The TicTacToe class will be reused in a later lab requiring the data members and method signatures listed. If you change these items, you will have to rewrite this class later. Not fun... 8.Hint: On the above sample run, make notes as to the order of the TicTacToe method calls. This should help you write the client. 9.Optional: When a game completes, provide an option to play again. 10.Optional: Allow each player to select a marker, either their own or from a list of available markers. 11.The TicTacToe class should be documented using Javadocs. Javadocs are not needed for the client class, although your name should be included within comments at the top of the program. 12.Adhere to the Style Guide for both classes. Evaluation: Classes must compile without syntax errors or will not be evaluated. This lab is worth 25 points. Points will be distributed as follows: •TicTacToe class (18 points) ◦Use of a two-dimensional array ◦Definition of constructors, accessors, and mutators to support class fields ◦Definition of methods that support the objectives of the class ◦Methods produce correct results ◦Methods contain no end-user I/O ◦Code aheres to the style guide •Client class (6 points) ◦Supports communication with the end-user ◦Main method utilizes the TicTacToe service class to meet the objectives of the application ◦Code aheres to the style guide •On time (late penalty of 7 points assessed for projects submitted late) My Client Application so far : Under megaupload, extension ?d=3HZW436R My Game Application so far: Under megaupload, extension ?d=1BMXLN3F

Answers

players should be handled in the Client class. 3.Test the TicTacToe class first and create a method to test different features in the class. Work done so far: I have so far created a gameboard array with the initial state of characters '1' to '9'. public class TicTacToe { public char board[][] = { { '1', '2', '3' }, { '4', '5', '6' }, { '7', '8', '9' } }; } I am now trying to create the constructors, accessor, and mutator methods as instructed in the class UML diagram. However I am having difficulty understanding what these methods should do. Could someone please further explain to me what is asked of me in this section? A: Constructors A constructor for a class is a kind of method which creates an instance of a class--it sets an initial state for the instance. The constructor you were asked to create sets some initial values for the data fields in the class TicTacToe. For the default constructor, set default values for the data fields: player1 and player2 to "Player 1" and "Player 2" the marker1 to 'X' marker2 to '

Answered by paularojas

We have mentors from

Contact support