<p>so i was practicing labs for extra credit and my teacher hasnt taught us matrix yet so i was wondering if anyone could help me out with this lab.</p>
<p>View</a> image: photo Rubric</p>
<p>import java.util.Scanner;
import static java.lang.System.*;</p>
<p>public class TicTacToe
{
private char[][] mat;</p>
<pre><code>public TicTacToe()
{
for (int i = 0; i < mat.length; ++i)
{
for (int j = 0; j < mat.length; ++j)
{
mat*[j] = ' ';
}
}
}
public TicTacToe(String game)
{
}
public String getWinner()
{
return "";
}
public String toString()
{
String output="";
return output+"
";
}
</code></pre>
<p>}</p>
<p>TicTacToeRunner.java
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
import static java.lang.System.*;</p>
<p>public class TicTacToeRunner
{
public static void main( String args[] ) throws IOException
{</p>
<pre><code>}
</code></pre>
<p>}</p>
<p>tictactoe.dat
5
XXXOOXXOO
OXOOXOXOX
OXOXXOXOO
OXXOXOXOO
XOXOOOXXO</p>
<p>help anyone. i’ve been trying to learn but my teacher is horrible at teaching. trying to self learn but its impossible</p>
<p>you haven’t exactly asked a question …</p>
<p>well i’ve been trying to finish this lab. just dont know if i did some of it right or not. i didnt fill much out but thats because i work really slow. what i need help with is in the main right now. so far i have this</p>
<pre><code> Scanner x = new Scanner(new File(“tictactoe.dat”));
</code></pre>
<p>if anyone could help. i have a deadline and my teacher will not help me. says i gotta do it by the end of this week or else i get offic refferal</p>
<p>ok so i’ve run into some problems. can someone run through the code and tell me what it is i need to fix because my program doesnt run</p>
<p>import java.util.Scanner;
import static java.lang.System.*;</p>
<p>public class TicTacToe
{
private char[][] mat;
int once =0;
int luck = 0;
int[] arrays = new int[3];</p>
<pre><code>public TicTacToe()
{
mat = new char[3][3];
}
public TicTacToe(String game)
{
if(once == 0)
{
mat = new char[3][3];
once++;
}
for(int row =0;row < 3; row++)
{
for(int col = 0; col < 3;col++)
{
if(luck >= game.length() + 1)
{
luck =0;
}
mat[row][col] = game.charAt(luck);
luck++;
}
}
</code></pre>
<p>}
public String getWinner()
{
int steps = 0;
String winnerX = null;
String winnerY = null;
for(int x = 0; x < mat.length;x++)
{
if(mat[x][0]==mat[x][1] && mat[x][0] == mat[x][2])
{
if(mat[x][0] == ‘X’)
{
winnerX = " winner is X";
steps = 1;
}
else
{
winnerY = “winner is Y”;
steps = 2;
}
}
}
for(int i = 0; i < mat.length; i++)
{
if(mat[0]==mat[1] && mat[0]* == mat[2])
{
if(mat[0] == ‘X’)
{
winnerX = " winner is X";
steps = 3;
}
else
{
winnerY = “winner is Y”;
steps = 4;
}
}
}
for(int k = 0; k < mat.length; k++)
if(mat[k][0]==mat[k][1] && mat[k][0] == mat[k][2])
{
if(mat[0][k-1] == ‘X’)
{
winnerX = " winner is X";
steps = 5;
}
else
{
winnerY = “winner is Y”;
steps = 6;
}
}
//0 = none
//1 = horizontal x
//2 = horizontal y
//3 = vertical x
//4 = vertical y
if(steps == 1)
{
return “winner is X wins horizontal!”;
}
else if(steps == 2)
{
return “winner is Y wins horizontal”;
}
else if(steps == 3)
{
return “winner is X wins vertical!”;
}
else if(steps == 4)
{
return “winner is Y wins vertical!”;
}
else if(steps == 5)
{
return “winner is X wins diaganolly!”;
}
else if(steps == 6)
{
return “winner is Y wins diaganolly!”;
}</p>
<pre><code> return “tie”;
</code></pre>
<p>}</p>
<pre><code> public String toString()
{
String output="";
for(int row =0;row < mat.length; row++)
{
for(int col = 0; col < mat[row].length;col++)
{
output = output + " " + mat[row][col];
}
output = output + "
";
}
return output;
}
</code></pre>
<p>}</p>
<p>main</p>
<p>import java.io.File;
import java.io.IOException;
import java.util.Scanner;
import static java.lang.System.*;</p>
<p>public class TicTacToeDH2
{
public static void main( String args[] ) throws IOException
{
TicTacToe test = new TicTacToe();
Scanner scan = new Scanner(new File(“tictactoe.dat”));
int row = scan.nextInt();
scan.nextLine();
for(int i = 0; i < row; i++)
{
String line = scan.nextLine();
test = new TicTacToe(line);
System.out.println(test);
System.out.println(test.getWinner());
System.out.println();
System.out.println();
}
}
}</p>