Displaying the board using a nested

Assignment Help Basic Computer Science
Reference no: EM131944993

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

Reference no: EM131944993

Questions Cloud

Most advantageous capital structure of corporation : Imagine that you are a certified Public Accountant (CPA) with a new client who needs an opinion on the most advantageous capital structure of a corporation.
Create a business brief - Define key items or variables : Business Analytics Academic Submissions and Evaluation. For this assignment you will create a business brief of 3 pages
What is the purpose of implementing projects in a business : Address common misconceptions that the company's management may have regarding the use of a project manager to expand the business.
Detection and mitigation : Forensics appears to be highly undeveloped when addressing insider threats. Insider behaviour may be close to the expected behaviour
Displaying the board using a nested : 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.
How does data leakage occur in an organization : How does data leakage occur in an organization? What are the common causes of this problem?
Cybersecurity and computer security : What are the similarities and differences between cybersecurity and computer security.
How are the two types of operating systems similar : What inherent security controls are included with each operating system? How are the two types of operating systems similar?
Play with big enterprise security breaches : How much does human error come into play with big enterprise security breaches?

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Identifies the cost of computer

identifies the cost of computer components to configure a computer system (including all peripheral devices where needed) for use in one of the following four situations:

  Input devices

Compare how the gestures data is generated and represented for interpretation in each of the following input devices. In your comparison, consider the data formats (radio waves, electrical signal, sound, etc.), device drivers, operating systems suppo..

  Cores on computer systems

Assignment : Cores on Computer Systems:  Differentiate between multiprocessor systems and many-core systems in terms of power efficiency, cost benefit analysis, instructions processing efficiency, and packaging form factors.

  Prepare an annual budget in an excel spreadsheet

Prepare working solutions in Excel that will manage the annual budget

  Write a research paper in relation to a software design

Research paper in relation to a Software Design related topic

  Describe the forest, domain, ou, and trust configuration

Describe the forest, domain, OU, and trust configuration for Bluesky. Include a chart or diagram of the current configuration. Currently Bluesky has a single domain and default OU structure.

  Construct a truth table for the boolean expression

Construct a truth table for the Boolean expressions ABC + A'B'C' ABC + AB'C' + A'B'C' A(BC' + B'C)

  Evaluate the cost of materials

Evaluate the cost of materials

  The marie simulator

Depending on how comfortable you are with using the MARIE simulator after reading

  What is the main advantage of using master pages

What is the main advantage of using master pages. Explain the purpose and advantage of using styles.

  Describe the three fundamental models of distributed systems

Explain the two approaches to packet delivery by the network layer in Distributed Systems. Describe the three fundamental models of Distributed Systems

  Distinguish between caching and buffering

Distinguish between caching and buffering The failure model defines the ways in which failure may occur in order to provide an understanding of the effects of failure. Give one type of failure with a brief description of the failure

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd