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

  Are both necessary on every drawing you create

Drafters generally classify dimensions in two broad categories: size dimensions and location dimensions. What is the difference between them? Are both necessary on every drawing you create? Write a paragraph explaining your findings.

  Convert the table from unnormalised form

Convert the table from Unnormalised Form (UNF) to First Normal Form (1NF)

  Justify components of material list and resource requirement

I need to justify the components listed in the attached document names Materials List and Resource Requirements.

  Formulated the following lp problem

A manager has formulated the following LP problem. Draw the graph and find the optimal solution.

  Return the length of the shorter

Please help make a function shorter(l1, l2) that takes as inputs two lists l1 and l2, and that return the length of the shorter (of the two) lists.

  Examine the process of strategic management

Identify the major components of the strategic management process. Discuss how these components work together to create value for the organization.

  A mechanism for deciding when to report an rtp packet

Propose a mechanism for deciding when to report an RTP packet as lost. How does your mechanism compare with the TCP adaptive retransmission mechanisms of Section 5.2.6?

  Write a mips assembler program to do the following

Write a MIPS assembler program to do the following: 1. Get three integers from the keyboard 2. Calculate and display the sum of the integers

  Use a jframe or japplet as the primary interface

A simple GUI that enables the user to create and view ASCII animations. Requirements: Use a JFrame or JApplet as the primary interface Extend whatever Swing elements you need to create the animation Use at least one interface to handle events

  Describing the use of an olap data cube

Write a 2 to 3 page essay describing the use of an OLAP Data Cube. Your essay should also describe the operations of Drill Down, Roll Up, Slice, and Dice. Answer should be unique. Use APA format with proper citations

  Draw an activity diagram representing each step

Add exception handling to the activity diagram you developed in Exercise 2-15. Consider at least three exceptions (e.g., delivery person wrote down wrong address, delivery person brings wrong pizza, store out of anchovies).

  Describe a procedure that selects a key uniformly at random

Describe a procedure that selects a key uniformly at random from among the keys in the hash table and returns it in expected time O(L·(1+1/a)).

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