Question: Looking for a little help with this Java program Write a class called TicTakToe and declare a class constant named SIZE for size of the

Looking for a little help with this Java program

Write a class called TicTakToe and declare a class constant named SIZE for size of the board being equal to 3. Add three fields to the class: -board which stores a SIZE x SIZE array of characters. -playerOne which stores the symbol that the player uses -playerTwo which stores the symbol that player two uses. Add a constructor with parameters for the first player's mark and the second player's mark. It should initialize the board to contain all spaces. Then add accessor methods for the two player's marks. Next add a method called toString to the class with no parameters and returns a String that contains a drawing of the board, with row and column headers: here is how the output should look:

Looking for a little help with this Java program Write a class

Next write some methods for your program... one called rowIndexFromLocation with one parameter, which is a string that represents a location on the board. The parameter should have two characters. The rst of which selects the row (`1', `2', or `3'). This method converts the first character of the location to the array index such that row '1' is index 0, row '2' is index 1, etc. If the rst character does not represent a valid row, it should return -1...... The next method should be called columnIndexFromLocation with one parameter, which is a string that represents a location on the board. The parameter should have two characters. The second of which selects the column (`A', `B', or `C'). This method converts the second character of the location to the array index such that column `A' is index 0, column `B' is index 1, etc. If the second character does not represent a valid column, it should return -1.....next add method called isLocationPlayable with one parameter, a string that represents a location on the board. It should return a boolean. The parameter should have two characters representing the row and column of the board. This method should return true if the location has not yet been played and false otherwise..... Next write a getLocation method with parameter, a String, and it should return a char. The parameter is supposed to contain two characters. The first selects a row (`1', `2', or `3'), and the second a column (`A', `B', or `C'). If the parameter is valid, the method should return what is in that location on the board. If not, it should return a space..... Add a method called takeTrun with two parameters, the player number (1 or 2) and a location string as described in previous question and return whether the turn was successful. If the location string is valid, that location currently contains a space, and the player number is valid, the method should place that player's mark in that location...... Next add a method called didPlayerWin with one parameter, which is a player number (1 or 2), and should return whether the player has won(if the player has a row, column or diagonal filled)....... Next add a method called isBoardFilled with no parameters and returns a boolean. If no location on the board contains a space, it should return true. Otherwise, it should return false......

Next write a Main class for your program to create a game... add the following methods to the Main class.... add a static helper method called getMarks with one parameter, a Scanner and it should return an array of characters. This method should prompt the first player to select their mark, and then read a string from the keyboard. If this string contains more than one character, it should re-prompt the user and re-read strings repeatedly until it gets a one-character string. Then it should prompt the second player to select their mark and read a string from the keyboard. If this string contains more than one character or is the same mark chosen by the rst player, it should re-prompt and re-read repeatedly until the input is valid. The method should return an array of two characters in which the first position contains the first player's mark and the second contains the second player's mark..... next add a static helper method called getLocation with two parameters, a Scanner and a TicTacToe. It should retunr a String and prompt the user for a location into which they would like to place their mark. If that location is invalid in any way (with error messages below), or that location is already lled, it should repeatedly re-prompt and re-read until it gets valid input. It should return the final location chosen. (Error messages: 1. Error: a location must consist of two characters. 2.Error: the first charcter in a location must be '1', '2', or '3' 3. Error: the second character in a location must be 'A', 'B', or 'C'. 4. Error: that location has already been filled. ....... next add a static helper method called playGame with three parameters, a Scanner, an array of characters that holds the player's marks, and an integer that speci es which player (1 or 2 should go rst). It should construct a TicTacToe instanc eand then repeat the following steps until either a player has won the game or the board fills up. (1. print a picture of the board. 2. Print a message about whose turn it is 3. read and validate the location they would like to use 4. place the appropriate player's mark at the location ) when the game is over, it should print a message saying which player won or if it ended in a tie followed by a picture of the final board.....

Lastly, add a main method that constructs a Scanner for reading from the keyboard, read and validate the player's marks, and play a game of Tic-Tac-Toe with player 1 making the first move. Then it should ask whether or not the players would like to play again. If so, it should play another game, with player 2 making the first move, and continue asking about another game and alternating first moves until the players decide not to play another game. (example prompts.. 1. Would you like to play again? (y) 2. Error please answer 'y' or 'n' 3. Thanks for playing)

0 ! 123

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!