
Explanation of Solution
Modified Program:
//Define TicTacToe class
public class TicTacToe
{
//Declare and initialize the required variables
public static final int X = 1, O = -1;
public static final int EMPTY = 0;
//Declare the two dimensional game board variable
private int board[][] = new int[3][3];
//Declare current player variable
private int player;
//Define default constructor
public TicTacToe( )
{
/*Call clearBorad() method to clear the game board. */
clearBoard( );
}
//Define clearBoard() method
public void clearBoard( )
{
//Loop executes until 3 rows
for (int i = 0; i < 3; i++)
//Loop executes until 3 columns
for (int j = 0; j < 3; j++)
//Clear each and every cell
board[i][j] = EMPTY;
//Assign first player is "X"
player = X;
}
//Modified method
//Define modified putMark() method
public void putMark(int i, int j) throws IllegalStateException
{
//Check whether the rows and column missing
if ((i < 0) || (i > 2) || (j < 0) || (j > 2))
//Throw an IllegalStateException
throw new IllegalStateException("Invalid board position");
//Check whether the game board is not empty
if (board[i][j] != EMPTY)
//Throw an IllegalStateException
throw new IllegalStateException("Board position occupied");
//Assign current player into board
board[i][j] = player;
//Change the players
player = -player; // switch players (uses fact that O = - X)
}
/*Define the isWin() method to checks whether the board configuration is a win for given player.*/
public boolean isWin(int mark)
{
/*Return the board configuration for rows and columns. */
return ((board[0][0] + board[0][1] + board[0][2] == mark*3) || (board[1][0] + board[1][1] + board[1][2] == mark*3) || (board[2][0] + board[2][1] + board[2][2] == mark*3) || (board[0][0] + board[1][0] + board[2][0] == mark*3) || (board[0][1] + board[1][1] + board[2][1] == mark*3) || (board[0][2] + board[1][2] + board[2][2] == mark*3) || (board[0][0] + board[1][1] + board[2][2] == mark*3) || (board[2][0] + board[1][1] + board[0][2] == mark*3));
}
/* Define winner() method to returns the code for winning players or indicates "0" for tie the game or unfinished game.*/
public int winner( )
{
//Call the isWin() method to check the winning player is "X". */
if (isWin(X))
//Returns the code "X" for winning players
return(X);
//Otherwise, call the isWin() method to check the winning player is "O". */
else if (isWin(O))
//Returns the code "O" for winning players
return(O);
//Otherwise, exit the game
else
return(0);
}
/*Define toString() method to returns the current board for showing the simple character string. */
public String toString()
{
//Create an object for StringBuilder
StringBuilder sb = new StringBuilder();
//Loop executes until 3 rows
for (int i=0; i<3; i++)
{
//Loop executes until 3 columns
for (int j=0; j<3; j++)
{
//Match the character in board
switch (board[i][j])
{
/*If the row and column contains "X"...
Want to see the full answer?
Check out a sample textbook solution
Chapter 3 Solutions
Data Structures and Algorithms in Java
Additional Engineering Textbook Solutions
Starting Out with C++: Early Objects (9th Edition)
Web Development and Design Foundations with HTML5 (8th Edition)
Modern Database Management
Starting Out With Visual Basic (8th Edition)
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
INTERNATIONAL EDITION---Engineering Mechanics: Statics, 14th edition (SI unit)
- Minimum Study Hours per Week per Class Grade 15 A 12 B 9 C 6 D 0 F Application must be menu driven, and contain the following options: A. Determine Hours to Study B. Determine Grade C. Display Averages and Totals D. Quit Note: The user must be able to select any menu option in any order they want. And only exits the application when they choose. Menu option A -- Determine Hours to Study The program will READ in data from a text file named StudyHours.txt. This text file is created by you and will be submitted with your project. Your file must include 5 additional records in addition to the example at the end of this document (10 total). StudyHours.txt contains the following format: First line: Full name Second line: Number of credits Third line: Grade desired for each class The user must correct any bad data in the application. For example, if the file contains a letter grade of 'K', which is not a possible letter grade, they are asked to correct the information. You DO NOT need to…arrow_forwardNO AI USE PLEASEarrow_forwardRSA decryption: You are given the following RSA values: n = 9797, e = 7, d = 4111. Some ciphertext was received: c = 7321. Based on that information, compute the plaintext message m. Show all your work along the way. No Use of AI pleasearrow_forward
- (25 points) What are the use cases in which public key encryption would be useless? In light of what we discussed in class. would the internet be where it is today without the COIS-4370H-A-F01-2025FA-OSH Computer & Info Security Ords. City any sources you use. Remember to frame your answer in light of what was discussed in class.arrow_forward2) You have learned in class the major steps that occur when a laptop requests a webpage after connecting to a network. In this assignment, you will apply that knowledge to another scenario: opening and playing a YouTube video that resides in Google's data-center infrastructure. Explain, in as much detail as you can, all the steps involved from your device's initial connection to the home/university network, to DNS resolution, routing across multiple networks, reaching Google's servers, and finally receiving the video data. To support your explanation, use tools such as ipconfig, nslookup, and tracert on your own computer, as well as any online IP-lookup tools of your choice. For each stage, include relevant information such as IP addresses, MAC addresses, router hops, and any other details you can gather. You are not expected to find every piece of information, but be as comprehensive as possible based on what you have learned in class, and justify your reasoning with screenshots from…arrow_forwardPlease no use of AIarrow_forward
- help me with this project. provide what I should put on each slide (words, example images, etc); example Slide 1: Intro. here are the directions: Submit a report that includes the source code, compiled code, description of the algorithm(s) implemented, data structures used, implementation details including time complexity analysis, sample inputs/outputs, and a conclusion section.arrow_forwardThese questions are for a Computer Science course called "Theory of Computation". Provide the answers and process to the answers by using steps without little to no explanations. Provide drawings if necessary based on the questions for 1, 2a-c, and 3 based on these images provided.arrow_forwardObjective: The objective of this assignment is to gain practice with pen testing a live web application running on a remote server. The live web application is a known vulnerable web application called DVWA (Damn Vulnerable Web Application) with security settings set to low. The web app is running on an AWS EC2 (Elastic Compute Cloud) instance running Ubuntu 22. Note: The point of this assignment is to step it up a notch, we learnt about different web application vulnerabilities and applied that knowledge, now we are going to pen test and enumerable the vulnerabilities of a web app + the underlying infrastructure it is running on. Before you begin please find out what your IP address is and place it in this sheet so that I can track who is doing what: IP Addresses.docx . Tasks: 1- Start by connecting to the target, I did not install a TLS certificate on purpose that is why you are going to connect via http and not via https: http://3.99.221.134/dvwa/login.php 2- Broken Authentication:…arrow_forward
EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
Systems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage Learning



