Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

One constructor should take an int parameter indicating the size of the TTT board to be used (in case someone wanted to play a variation

image text in transcribed

One constructor should take an int parameter indicating the size of the TTT board to be used (in case someone wanted to play a variation of TTT where a player needed, say, four-in-a-row to win). The other constructor should take no arguments, indicating that a standard size 3 board should be used. If size is less than 1, your constructor should throw an IllegalArgumentException.

The method get should return the character that is at position (r,c) or a space character ' ' if no character is at that position. The method set should set position (r,c) to be character ch. It should not be considered an error to use set to change an already set character to another one, including back to a space. If (r,c) is out-of-bounds, throw an IndexOutOfBoundsException.

The method size should return the dimension of the TTT board. It will be whatever size was passed to the constructor, or 3 if no value was passed to the constructor. All values for r and c in the range 0..size()-1should be legal for set and get.

The method winner should determine whether there are size() of the same character in a row, either horizontally, vertically, or diagonally. If there is, the found character should be returned, otherwise a space character ' ' should be returned. If more than one winning sequence is found, you may return any of them.

The method toString should return a string representation of the board. For example, the board shown above as a single string is " | | -+-+- O| | -+-+- |X| ". Notice that is used to advance the output to the next line, so even though this is a single string, when it is printed it will appear as five lines on the screen. For testing purposes it is essential that each row of output is exactly 2 * size() - 1 characters (not counting the ), that the returned string does not end in , and that it uses the same pattern of characters as the example board above.

Your class should have a public class constant DEFAULT_SIZE set to 3 so that code can easily know what the default size of boards are. (Look up "classes, constants" in your textbook index if you don't recall how and where to define them.)

Write a class named TTTBoard. Its purpose is to model a Tic-Tac-Toe game board. we will refer to each position of the board as an ordered pair (r c) where the upper-left position of the board s at Co, x at position (2,1) and an o at position (1,0) andincreases do ard and c increases to he So e ollo in board has an IXI The following public methods should be supported in TTTBoard public TTTBoardCint size) public TTTBoard) public char getCint r, int c) public void setCint r, int c,char ch) public int size) public char winner public String tostringo Write a class named TTTBoard. Its purpose is to model a Tic-Tac-Toe game board. we will refer to each position of the board as an ordered pair (r c) where the upper-left position of the board s at Co, x at position (2,1) and an o at position (1,0) andincreases do ard and c increases to he So e ollo in board has an IXI The following public methods should be supported in TTTBoard public TTTBoardCint size) public TTTBoard) public char getCint r, int c) public void setCint r, int c,char ch) public int size) public char winner public String tostringo

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts International Edition

Authors: David M. Kroenke

6th Edition International Edition

0133098222, 978-0133098228

Students also viewed these Databases questions

Question

Was Ms. Jones a good friend of Mr. Thompson? (Stage 3) AppendixLO1

Answered: 1 week ago