Question: NO LOOPS ALLOWED!!!!!!! Write a Java program that finds the winner of a randomly completed tic-tac-toe board. Your code will assign each spot on the

NO LOOPS ALLOWED!!!!!!!

Write a Java program that finds the winner of a randomly completed tic-tac-toe board.

Your code will assign each spot on the board randomly with '_', 'O', 'X' and determines if O, X, both, or none wins.

Create a project and class named Lab5FirstnameLastname using your actual first and last names in NetBeans to hold your program.

Let your variables b11, b12, b13, b21, b22, b23, b31, b32, b33 represent the 3 x 3 tic tac toe board as follows:

b11 b12 b13

b21 b22 b23

b31 b32 b33

Write a method named setValue() which doesnt take any parameters but will return one of 3 possible random characters: '_', 'O', 'X' to the caller. Call this method from your main method to assign each of your board variables with '_', 'O', or 'X'. You can use the following code to generate the random characters returned by your setValue() method:

String ox = "OX_";

Random rnd = new Random();

int n = rnd.nextInt(3);

char c = ox.charAt(n);

Write a method named printBoard() which accepts the 9 board variables as parameters and outputs the result of the game to the console. This method MUST use printf to output the game board to the console using the format shown above. The method printBoard() will not return anything to the caller. Write a method named printResult() which accepts the 9 board variables as parameters and outputs the result of the game to the console. Remember, the possibilities for the result are that O can win, X can win, X & O both can win, or neither X or O wins. The method printResult() will not return anything to the caller. Use the following code to get your main method started:

import java.util.Scanner;

import java.util.Random;

class Lab5 {

public static void main(String[] args) {

char b11, b12, b13,

b21, b22, b23,

b31, b32, b33;

//code to call the setValue() method to assign values to board variables

//code to call the printBoard() method //code to call the printResult() method }

//setValue() method goes here

//printBoard() method goes here

//printResult() method goes here }

Additional Assignment Requirements

1. You may not use any concepts not yet taught in this course like loops

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!