Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me with this AP COMPUTER SCIENCE A Lab in Java. Here are the description of the lab and the initial code provided: In

Please help me with this AP COMPUTER SCIENCE A Lab in Java. Here are the description of the lab and the initial code provided:

In this lab you will create a working TicTacToe board and game to play against another player.

The TicTacToe board is made of chars. A char is java is a single letter denoted by single quotes(eg. 'A' or '2'). You will write a series a methods to set up the board, mark a spot on the board with 'x' or 'o', switch players, and check for a win.

### Directions: 1. Complete each method in the TicTacToe class. 2. Using Scanner you will test your code in Main, similarly to the Blackjack setup. 3. Let me know when you are done so we can play!

Initial code in TicTacToe.Java:

public class TicTacToe { private char[][] board; private char currentPlayerMark;

//initialize board to a 3x3 board //set currentPlayerMark to 'x' public TicTacToe() {

}

//set each space on the board to '-' public void initializeBoard() {

}

//print the current board // items on the board should be separated by a space public void printBoard() {

}

// this method will return true if the board is full // and false otherwise public boolean isBoardFull() { return false; }

//this method will return true if a player has won the game // this method uses modularity by checking for a win // in the rows, columns, or diagonals public boolean checkForWin() { return false; }

//this method specifically checks the rows for a win public boolean checkRowsForWin() { return false; }

//this method specifically checks the columns for a win public boolean checkColumnsForWin() { return false; }

//this method specifically checks the diagonals for a win public boolean checkDiagonalsForWin() { return false; }

//this method will chek the three specified characters passed as paramters // to see if all three are the same 'x' or 'o' letter. // if so it will return true private boolean checkRowCol(char c1, char c2, char c3) { return false; }

// this method will swap the currentPlayer variable between 'o' and 'x' public void changePlayer() {

}

// this method will place the correct char onto the specified row & col. // Return true if it was a valid placement // In order for a placement to be valid the following must be true: // the parameters correspond to an actual row or column in our board, // & the spot must be empty. // Otherwise, no change to the board will be made and the method will return false public boolean placeMark(int row, int col) { return false; } }

Initial Code in Main.Java:

import java.util.Scanner; import java.util.Arrays;

class Main { public static void main(String[] args) {

//declare and instantiate a new TicTacToe game

} }

Please help me complete the missing code in TicTacToe class and the main class according to the lab description! Thanks so much!

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

Data Analysis Using SQL And Excel

Authors: Gordon S Linoff

2nd Edition

111902143X, 9781119021438

More Books

Students also viewed these Databases questions