Question

Objective: Create a Tic-Tac-Toe program for 2 players that allows the players to play for as many games as they want, keeping track of the board and winners (or ties). The TicTacToe class will implement the game. Include a three-by-three two-dimensional array as a private data member to create the board. All methods must have appropriate javadoc comments.

Requirements:
1) Display the board before each move.
2) Get a move - loop until a valid move
3) Keep track of the number of games won by Player 1, the number of games won by Player 2 and the number of Ties
4) Output the winner after each game
5) Loop until no more games
6) At the end of all the games output the number of games won by player 1, the number of games won by player 2 and the number of ties
Upload the design (algorithm), UML Diagram, class implementation (.java) and main - driver (.java) files.

Algorithm Steps:
1. Show user board
a. If 1st move, board shown as empty.
2. Prompt the user for which box they want as their input
a. Keep track of player 1 or 2 (X or O)
b. Tell user how to enter(rows and columns)
c. Read in their entry into row, column variable
3. Check input
a. Make sure row and column input is valid.(Exists in board)
b. Make sure row and column input in blank.
c. If is valid, go to 4, otherwise repeat 1
4. Place user’s move into the array (on the board)
a. Mark entry row and column with X or O (1 or 0) depending on player
5. Check array (board) for winner or full.
a. Look to see if rows/columns of same values
b. Look to see if all array indices are filled in
6. Once checked, go back to #1 with new player and repeat until checked is valid (win or tie becomes true)
7. If winner or tie, up the variables for number of wins and ties. (keep track of wins and ties)
a. 1= win for player 1, 2 = win for player2, 3= tie

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

import java.util.Scanner;

public class TicTacToe {

private char[][] board; //Board to store game state
private Scanner input;                //Input for users
private int moves, game;                //State of total games

public TicTacToe()
{
input = new Scanner(System.in);
board = new char[3][3];
moves = 0;
game = 0;
}

public void runGame()
{
int p1w = 0, p2w = 0, ties = 0; //Game results
int winner;
System.out.println("Welcome to Tic Tac Toe");
char answer;
resetGame(); //Reset game board and start at game 1
while(true)
{
System.out.println("Game: " + game);
while(true)
{
displayBoard(); //Display the board
getMove(1); //Get player 1's move
moves++;...

This is only a preview of the solution. Please use the purchase button to see the entire solution

Related Homework Solutions

5 Commandments For Computer Ethics
Homework Solution
$10.00
Computer Science
Programming
Commandments
Computer Ethics
Examples
Harm
Stealing Files
False Witness
Software
Resources
Authorization
Intellectual Output
Social Consequences
Respect
Gradebook Using Java Programming
Homework Solution
$20.00
Java
Programming
Computer Science
Random Numbers
Scores
Students
Input
Output
Loops
Statements
Conditions
Average Values
Variables
Mathematics
Bellman-Ford Algorithm in Java
Homework Solution
$40.00
Programming
Computer Science
Java
Bellman-Ford Algorithm
Matrix
Cost
Distance
Iterations
Loops
Conditions
Vertices
Edges
Paths
Classes in Java Programming
Homework Solution
$20.00
Java
Programming
Coding
Classes
OOP
Instances
Variables
Constructor
Parameters
Loops
Strings
Integers
Conditions
Statements
Setters
Getters
Error Handling
Get help from a qualified tutor
Live Chats