Finished that assignment(Although if you could tell me how I could get there to be two 0's after the decimal point instead of one for the output, that'd be helpful. Currently it only shows one 0 after the decimal point in the output, I.E. the user puts in 24 and the screen shows 24.0, and I'm looking for 24.00), although stuck on the last one.
Problem states:
"In this exercise you will create a TicTacToe game using an array to represent the board. Even though the board is 2-dimensional, we can still use a 1-dimensional array to represent it as you will see. Create a TicTacToe class and give it one attribute that is a 1-dimensional array of char. Create an init method that creates a 9 element array for this attribute and initializes each element to a blank space. Create a second method named SetSquare that accepts the index number of a square and a character to place there. This method should check to see if a valid number has been entered for the square(0-8) and whether the square has already been filled. If either of those is true, the player loses their turn. If good values have been passed in, the square should be set to the character that was passed in. Finally, create a third method called display. This method should print out the game board.
This is what I have so far. I just feel like I'm going in the completely wrong direction for this and I'm clueless as to how to fix it(besides that it is incomplete code).
Code:
public class TicTacToe
{
public int gameBoard;
public int endNumber = 8;
public void init()
{
int[][]gameBoard = new int[3][3];
}
public void setSquare(int squareNumber, int player)
{
if((squareNumber < 0)&&(squareNumber > endNumber))
{
System.out.println("Bad square--lose turn");
}
if((squareNumber == 0)&&(player == 1))
{
gameBoard[0,0]=X;
}
if((squareNumber == 1)&&(player == 1))
{
gameBoard[0,1]=X;
}
if((squareNumber == 2)&&(player == 1))
{
gameBoard[0,2]=X;
}
if((squareNumber == 3)&&(player == 1))
{
gameBoard[1,0]=X;
}
if((squareNumber == 4)&&(player == 1))
{
gameBoard[1,1]=X;
}
if((squareNumber == 5)&&(player == 1))
{
gameBoard[1,2]=X;
}
if((squareNumber == 6)&&(player == 1))
{
gameBoard[2,0]=X;
}
if((squareNumber == 7)&&(player == 1))
{
gameBoard[2,1]=X;
}
if((squareNumber == 8)&&(player == 1))
{
gameBoard[2,2]=X;
}
if((squareNumber == 0)&&(player == 2))
{
gameBoard[0,0]=O;
}
if((squareNumber == 1)&&(player == 2))
{
gameBoard[0,1]=O;
}
if((squareNumber == 2)&&(player == 2))
{
gameBoard[0,2]=O;
}
if((squareNumber == 3)&&(player == 2))
{
gameBoard[1,0]=O;
}
if((squareNumber == 4)&&(player == 2))
{
gameBoard[1,1]=O;
}
if((squareNumber == 5)&&(player == 2))
{
gameBoard[1,2]=O;
}
if((squareNumber == 6)&&(player == 2))
{
gameBoard[2,0]=O;
}
if((squareNumber == 7)&&(player == 2))
{
gameBoard[2,1]=O;
}
if((squareNumber == 8)&&(player == 2))
{
gameBoard[2,2]=O;
}