Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

In a game of tic-tac-toe, 2 players take turns marking an available cell in a 3x3 grid with their respective tokens (either X or O). When one player has placed 3 tokens in a horizontal, vertical, or diagonal row on the grid, the game is over and that player has won. A draw (no winner) occurs when all the cells on the grid have been filled with tokens and neither player has achieved a win. Design a program for playing tic-tac-toe.

The program prompts 2 players to enter an X token and O token alternately. Whenever a token is entered, the program redisplays the board on the console and determines the status of the game (win, draw or continue). 

MUST USE THE FOLLOWING TWO CLASSES IN THE SOLUTION:

TicTacToe Class

This class is the driver program. It contains one method: main() which uses the GameBoard class to play the game of Tic-Tac-Toe. It also contains a flag 'keepPlaying' that is set when the game is over (win or draw).

Here is the UML:

TicTacToe

+ main(String): void

Here is the algorithm:

displayBoard
while (keepPlaying)
    makeAMove X
    diplayBoard
    if (isWon X) 
        X player won
    else if (isDraw)
        No winner
    if (keepPlaying) //no need to continue if X won/draw
        displayBoard
        makeAMove O
        if (isWon O)
            O player won
        else if (isDraw)
            No winner

GameBoard Class

This class holds the reference to the 2-D array representing the board and contains all the methods needed to display the board, have one user make a move, check if there is a winner, and check if there is a draw.

The constructor should initialize each cell to a character of choice (I used '$' but can use anything even blank ' '). Use a nested loop to:

Here is the UML:

GameBoard

- board: char[ ][ ]

- input: Scanner

+ GameBoard(): GameBoard

+ displayBoard(): void

+ makeAMove(char): void

+ isDraw(): boolean

+ isWon(char): boolean

The ONLY classes may use are: GameBoard and the driver: TicTacToe

Input

One user acts as BOTH player X and player O and is prompted to enter the row and then the column they want. Example (user input in bold):

Enter a row for player X: 1

Enter a column for player X: 2

Hint: 

Do one method at a time and make it work before moving on to the next method. Start with displaying the board using a nested for-loop.

Note: in the constructor for GameBoard class, use nested loops to initialize the 2-D array named board

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M92783649
  • Price:- $20

Priced at Now at $20, Verified Solution

Have any Question?


Related Questions in Computer Engineering

This requires to use minitabthe following are the results

This requires to use Minitab The following are the results from a 2 5  design: Treatment       Response            Treatment       Response (1)                    700                     e                   800 a         ...

What type of economic system does norway have explain some

What type of economic system does Norway have? Explain some of the benefits of this system to the country and some of the drawbacks

We are evaluating a project that costs 1120000 has a

We are evaluating a project that costs $1,120,000, has a ten-year life, and has no salvage value. Assume that depreciation is straight-line to zero over the life of the project. Sales are projected at 64,000 units per ye ...

Question responsive frameworks and libraries provide

Question : Responsive frameworks and libraries provide convenience when creating a modern website. Discuss at least three design options, such as hiding content or layout changes, that would be beneficial for a responsiv ...

Question rivests distinguished point dp method is a

Question : Rivest's "distinguished point" (DP) method is a variable length hash chain where all chain end points have the same d-bit suffix. In the precomputation phase, a chain is computed until a value is output with t ...

Show your steps of how you found your calculations please

Show your steps of how you found your calculations. Please type reponse. Suppose the daytime processing load consists of 60% CPU activity and 40% disk activity. Your customers are complaining that the system is slow. Aft ...

How can businesses use technology and relationships to

How can businesses use technology and relationships to reduce their environmental impact?

Suppose that the demand curve for tickets to see a football

Suppose that the demand curve for tickets to see a football team play a game is given by Q = 80,000 - 40P and marginal cost is zero. The team's stadium can host 75,000 fans. 1) How many tickets would the team sell if it ...

Question suppose we have a hash table which has the hash

Question : Suppose we have a hash table which has the hash function integer % 13. For Quadratic and Linear Probing, what sequence of 13 different integers > 0 (positive) would create a worst-case situation over the entir ...

Pablo bought some rural property in oconee county that is

Pablo bought some rural property in Oconee County that is rumored to be part of an expansion of the Epps Bridge Center phenomenon. The developer of the party told him that the property could triple in value under the exp ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As