Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lab Goal : This lab was designed to teach you how to use a matrix, an array of arrays. Lab Description : Read in the

Lab Goal : This lab was designed to teach you how to use a matrix, an array of arrays.

Lab Description : Read in the values for a tic tac toe game and evaluate whether X or O won the game. The first number in the files represents the number of data sets to follow. Each data set will contain a 9 letter string. Each 9 letter string contains a complete tic tac toe game.

Files Needed ::

TicTacToe.java

TicTacToeRunner.java (Main.java in Repl.it)

tictactoe.dat

Sample Data :

5# of data sets in the file - 5

XXXOOXXOO

OXOOXOXOX

OXOXXOXOO

OXXOXOXOO

XOXOOOXXO

Sample Output :

X X X

O O X

X O O

X wins horizontally!

O X O

O X O

X O X

cat's game - no winner!

O X O

X X O

X O O

O wins vertically!

O X X

O X O

X O O

X wins diagonally!

X O X

O O O

X X O

O wins horizontally!

algorithm help

The determineWinner method goes through the matrix to find a winner. It checks for a horizontal winner first. Then, it checks for a vertical winner. Lastly, it checks for a diagonal winner. It must also check for a draw. A draw occurs if neither player wins.

You will read in each game from a file and store each game in a matrix. The file will have multiple games in it.

image text in transcribedimage text in transcribedimage text in transcribed

4 Main.java 1 import java.io.File; 2 import java.io.IOException; 3 import java.util.Scanner; import static java.lang.System. 5. //Name --> 6 /* 7 algorithm help The determineWinner method goes through the matrix to find a winner. It checks for a horizontal winner first. Then, it checks for a vertical winner. Lastly, it checks for a diagonal winner. It must also check for a draw. A draw occurs if neither player wins. You will read in each game from a file and store each game in a matrix. The file will have multiple games in it. 9 10 public class Main 11 12 public static void main( String args[]) throws IOException 13 { 14 15 } 16 ] tictactoe.dat x 1 2 3 5 4 5 6 7 OXOXXOXO0 XOXO00XXO 1 4 TicTacToe.java import java.util.Scanner; 2 import static java.lang.System.*; 3 public class Tictactoe 5 { 6 private char[][] mat; 7 8 public Tictactoe() 9 { 10 11 12 } 13 14 public TicTacToe(String game) 15 { 16 17 18 } 19 20 public String getWinner() 21 { 22 23 return 24 } 25 26 public String toString() 27 { 28 String output=""; 29 30 return output+" "; 31 } 32 } 33

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

Flash XML Applications Use AS2 And AS3 To Create Photo Galleries Menus And Databases

Authors: Joachim Schnier

1st Edition

0240809173, 978-0240809175

More Books

Students also viewed these Databases questions

Question

What is the purpose of the Salary Structure Table?

Answered: 1 week ago

Question

What is the scope and use of a Job Family Table?

Answered: 1 week ago