(1) Divide the content pane into two.
(2) In the first pane, create a 3x3 grid for Tic Tac Toe using JButton.
(3) You should to be able to play the game with a second human player by just clicking the buttons.
(4) Increase the font size to fill each square of the grid with either a "X" or an "O".
(5) The second pane is for setting the ReStart Button and the text area.
(6) Additionally create a 3x3 two dimensional array called play, and store moves in it as the game is progressing.
(7) Using this array, declare a winner or a draw.
(8) Imagine what should happen before a game begins or play a game against yourself to understand what all you have to do before one plays the game.
(9) After that plan what classes you need.
(10) design your game and show to your lab instructors. When they approve the plan, go ahead and code it.
Modify the game so that a human player plays the game with a computer that uses random moves.
Part3: (optional extra credit)
Modify the game so that a human player plays the game with a computer that makes smart moves.
What does it mean for a computer to make a smart move?
The computer looks at the game position, then for each possible move, the computer analyzes all possible outcomes before it chooses the best move.
So you have to write an analysis method that would enable the computer do this.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

* TicTacToe class
* Contains back-end game logic
public class TicTacToe {
    public static String[] modesArray = {"Player vs Player", "Player vs Random Computer", "Player vs Intelligent Computer"};
    private String mode;
    private String[][] play;
    private String player = "X";
    // Constructor
    public TicTacToe(String mode) {
       this.mode = mode;
       play = new String[3][3];
    // Get current player
    public String player() {
       return player;
    // Get current mode
    public void mode(String mode) {
       this.mode = mode;
    // Get player at specified tile
    public String get(int i, int j) {
       return play[i][j];
    // Make move at specified tile
    public void move(int i, int j) {
       if (winner().equals("")) {
            if (play[i][j].equals("")) {
                play[i][j] = player;
    // Transition to next move
    private void next() {
       if (winner().equals("")) {
            if (player.equals("X")) {
                player = "O";
            } else {
                player = "X";
       if (mode.equals(modesArray[1])) {
       } else if (mode.equals(modesArray[2])) {
       if (winner().equals("")) {
            if (player.equals("X")) {
                player = "O";
            } else {
                player = "X";
    // Method to perform random computer move
    private void computerRandom() {
       if (winner().equals("")) {
            while (true) {
                int i = (int)(Math.random()*3);
                int j = (int)(Math.random()*3);
                if (play[i][j].equals("")) {
                   play[i][j] = player;
    // Method to perform intelligent computer move
    private void computerIntelligent() {
       if (winner().equals("")) {
            String computer = player;
            String other;
            if (computer.equals("X")) {
                other = "O";
            } else {

By purchasing this solution you'll be able to access the following files:

50% discount

$60.00 $30.00
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats