thingy.txt - Notepad File Edit Format View Help // Tic-Tac-Toe Game. import java.util.*; public class thingy{...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
thingy.txt - Notepad File Edit Format View Help // Tic-Tac-Toe Game. import java.util.*; public class thingy{ static String[] board; static String turn; // CheckWinner method will // decide the combination // of three box given below. static String checkWinner() { for (int a = 0; a < 8; a++) { String line = null; switch (a) { case 0: line = board [0] + board[1] + board [2]; break; case 1: line = board [3] + board[4] + board [5]; break. Ln 1. Col 1 100% Windows (CRLF) I UTF-8 X thingy.txt - Notepad File Edit Format View Help case 1: line = board [3] + board[4] + board [5]; break; case 2: line = board [6] + board [7] + board[8]; break; case 3: line board [0] + board[3] + board [6]; break; case 4: line board [1] + board [4] + board [7]; break; case 5: line = board [2] + board [5] + board [8]; break; case 6: line board [0] + board [4] + board [8]; break; case 7: line board [2] + board [4] + board [6]; break; } //For X winner if (line equals("XXX")) { Ln 1, Col 1 100% Windows (CRLF) UTF-8 X thingy.txt - Notepad File Edit Format View Help } //For X winner if (line.equals("XXX")) { return "X"; } // For 0 winner else if (line.equals("000")) { return "0"; } } for (int a = 0; a < 9; a++) { if (Arrays.asList (board). contains (String.valueOf(a + 1))) { break; } else if (a == 8) { return "draw"; } } // To enter the X Or 0 at the exact place on board. System.out.println(turn + "'s turn; enter a slot number to place " + turn + " in:"); return null. In 1 Col1 100% Windows (CRLF) I UTF-8 X thingy.txt - Notepad File Edit Format View Help } // To enter the X Or 0 at the exact place on board. System.out.println(turn + "'s turn; enter a slot number to place " + turn + " in:"); return null; // To print out the board. 4 | 5 | 6 */ static void printBoard() { System.out.println("|---|---|---|"); System.out.println("| " + board [0] + " System.out.println(" + board [2] + " ["); ["); System.out.println("| + board [3] + " | " + board [5] + " ["); --|"); System.out.println(" System.out.println("| "+ board [6] +"|" + board [7] " " + board [8] + " "); System.out.println("|---|---|---|"); " + board [1] + " + board [4]+"| Ln 1, Col 1 100% Windows (CRLF) UTF-8 X thingy.txt - Notepad File Edit Format View Help System.out.println("| " + board [6] + System.out.println("|---|---|---|"); } public static void main(String[] args) { Scanner in = new Scanner(System.in); board = new String [9]; turn = "X"; String winner = null; for (int a = 0; a < 9; a++) { } board [a] =String.valueOf(a + 1); System.out.println("Welcome to 3x3 Tic Tac Toe."); printBoard(); | " + board[7] + " | " + board [8] + " "); System.out.println("X will play first. Enter a slot number to place X in:"); while (winner == null) { int numInput; // Excention handling Ln 1, Col 1 100% Windows (CRLF) I UTF-8 thingy.txt - Notepad File Edit Format View Help // Exception handling. // numInput will take input from user like from 1 to 9. // If it is not in range from 1 to 9. // then it will show you an error "Invalid input." try { numInput = in.nextInt(); if (!(numInput > 0 && numInput thingy.txt - Notepad File Edit Format View Help board [numInput if (turn.equals("X")) { turn = "0"; } else { } 1] = turn; turn = "X"; } else { printBoard(); winner checkWinner(); System.out.println("Slot already taken; re-enter slot number: "); } // If no one win or lose from both player x and 0. // then here is the logic to print "draw". if (winner.equals IgnoreCase("draw")) { System.out.println("It's a draw! Thanks for playing."); } Ln 1. Col 1 100% Windows (CRLF) I UTF-8 thingy.txt - Notepad File Edit Format View Help } } } printBoard(); winner = checkWinner(); } else { } } System.out.println("Slot already taken; re-enter slot number: "); } // If no one win or lose from both player x and 0. // then here is the logic to print "draw". if (winner.equals IgnoreCase("draw")) { System.out.println("It's a draw! Thanks for playing."); } // For winner -to display Congratulations! message. else { System.out.println("Congratulations! " + winner + "'s have won! Thanks for playing."); In 1 Col1 100% Windows (CRLE) I UTF-8 thingy.txt - Notepad File Edit Format View Help // Tic-Tac-Toe Game. import java.util.*; public class thingy{ static String[] board; static String turn; // CheckWinner method will // decide the combination // of three box given below. static String checkWinner() { for (int a = 0; a < 8; a++) { String line = null; switch (a) { case 0: line = board [0] + board[1] + board [2]; break; case 1: line = board [3] + board[4] + board [5]; break. Ln 1. Col 1 100% Windows (CRLF) I UTF-8 X thingy.txt - Notepad File Edit Format View Help // Tic-Tac-Toe Game. import java.util.*; public class thingy{ static String[] board; static String turn; // CheckWinner method will // decide the combination // of three box given below. static String checkWinner() { for (int a = 0; a < 8; a++) { String line = null; switch (a) { case 0: line = board [0] + board[1] + board [2]; break; case 1: line = board [3] + board[4] + board [5]; break. Ln 1. Col 1 100% Windows (CRLF) I UTF-8 X thingy.txt - Notepad File Edit Format View Help case 1: line = board [3] + board[4] + board [5]; break; case 2: line = board [6] + board [7] + board[8]; break; case 3: line board [0] + board[3] + board [6]; break; case 4: line board [1] + board [4] + board [7]; break; case 5: line = board [2] + board [5] + board [8]; break; case 6: line board [0] + board [4] + board [8]; break; case 7: line board [2] + board [4] + board [6]; break; } //For X winner if (line equals("XXX")) { Ln 1, Col 1 100% Windows (CRLF) UTF-8 X thingy.txt - Notepad File Edit Format View Help case 1: line = board [3] + board[4] + board [5]; break; case 2: line = board [6] + board [7] + board[8]; break; case 3: line board [0] + board[3] + board [6]; break; case 4: line board [1] + board [4] + board [7]; break; case 5: line = board [2] + board [5] + board [8]; break; case 6: line board [0] + board [4] + board [8]; break; case 7: line board [2] + board [4] + board [6]; break; } //For X winner if (line equals("XXX")) { Ln 1, Col 1 100% Windows (CRLF) UTF-8 X thingy.txt - Notepad File Edit Format View Help } //For X winner if (line.equals("XXX")) { return "X"; } // For 0 winner else if (line.equals("000")) { return "0"; } } for (int a = 0; a < 9; a++) { if (Arrays.asList (board). contains (String.valueOf(a + 1))) { break; } else if (a == 8) { return "draw"; } } // To enter the X Or 0 at the exact place on board. System.out.println(turn + "'s turn; enter a slot number to place " + turn + " in:"); return null. In 1 Col1 100% Windows (CRLF) I UTF-8 X thingy.txt - Notepad File Edit Format View Help } //For X winner if (line.equals("XXX")) { return "X"; } // For 0 winner else if (line.equals("000")) { return "0"; } } for (int a = 0; a < 9; a++) { if (Arrays.asList (board). contains (String.valueOf(a + 1))) { break; } else if (a == 8) { return "draw"; } } // To enter the X Or 0 at the exact place on board. System.out.println(turn + "'s turn; enter a slot number to place " + turn + " in:"); return null. In 1 Col1 100% Windows (CRLF) I UTF-8 X thingy.txt - Notepad File Edit Format View Help } // To enter the X Or 0 at the exact place on board. System.out.println(turn + "'s turn; enter a slot number to place " + turn + " in:"); return null; // To print out the board. 4 | 5 | 6 */ static void printBoard() { System.out.println("|---|---|---|"); System.out.println("| " + board [0] + " System.out.println(" + board [2] + " ["); ["); System.out.println("| + board [3] + " | " + board [5] + " ["); --|"); System.out.println(" System.out.println("| "+ board [6] +"|" + board [7] " " + board [8] + " "); System.out.println("|---|---|---|"); " + board [1] + " + board [4]+"| Ln 1, Col 1 100% Windows (CRLF) UTF-8 X thingy.txt - Notepad File Edit Format View Help } // To enter the X Or 0 at the exact place on board. System.out.println(turn + "'s turn; enter a slot number to place " + turn + " in:"); return null; // To print out the board. 4 | 5 | 6 */ static void printBoard() { System.out.println("|---|---|---|"); System.out.println("| " + board [0] + " System.out.println(" + board [2] + " ["); ["); System.out.println("| + board [3] + " | " + board [5] + " ["); --|"); System.out.println(" System.out.println("| "+ board [6] +"|" + board [7] " " + board [8] + " "); System.out.println("|---|---|---|"); " + board [1] + " + board [4]+"| Ln 1, Col 1 100% Windows (CRLF) UTF-8 X thingy.txt - Notepad File Edit Format View Help System.out.println("| " + board [6] + System.out.println("|---|---|---|"); } public static void main(String[] args) { Scanner in = new Scanner(System.in); board = new String [9]; turn = "X"; String winner = null; for (int a = 0; a < 9; a++) { } board [a] =String.valueOf(a + 1); System.out.println("Welcome to 3x3 Tic Tac Toe."); printBoard(); | " + board[7] + " | " + board [8] + " "); System.out.println("X will play first. Enter a slot number to place X in:"); while (winner == null) { int numInput; // Excention handling Ln 1, Col 1 100% Windows (CRLF) I UTF-8 thingy.txt - Notepad File Edit Format View Help System.out.println("| " + board [6] + System.out.println("|---|---|---|"); } public static void main(String[] args) { Scanner in = new Scanner(System.in); board = new String [9]; turn = "X"; String winner = null; for (int a = 0; a < 9; a++) { } board [a] =String.valueOf(a + 1); System.out.println("Welcome to 3x3 Tic Tac Toe."); printBoard(); | " + board[7] + " | " + board [8] + " "); System.out.println("X will play first. Enter a slot number to place X in:"); while (winner == null) { int numInput; // Excention handling Ln 1, Col 1 100% Windows (CRLF) I UTF-8 thingy.txt - Notepad File Edit Format View Help // Exception handling. // numInput will take input from user like from 1 to 9. // If it is not in range from 1 to 9. // then it will show you an error "Invalid input." try { numInput = in.nextInt(); if (!(numInput > 0 && numInput thingy.txt - Notepad File Edit Format View Help // Exception handling. // numInput will take input from user like from 1 to 9. // If it is not in range from 1 to 9. // then it will show you an error "Invalid input." try { numInput = in.nextInt(); if (!(numInput > 0 && numInput thingy.txt - Notepad File Edit Format View Help board [numInput if (turn.equals("X")) { turn = "0"; } else { } 1] = turn; turn = "X"; } else { printBoard(); winner checkWinner(); System.out.println("Slot already taken; re-enter slot number: "); } // If no one win or lose from both player x and 0. // then here is the logic to print "draw". if (winner.equals IgnoreCase("draw")) { System.out.println("It's a draw! Thanks for playing."); } Ln 1. Col 1 100% Windows (CRLF) I UTF-8 thingy.txt - Notepad File Edit Format View Help board [numInput if (turn.equals("X")) { turn = "0"; } else { } 1] = turn; turn = "X"; } else { printBoard(); winner checkWinner(); System.out.println("Slot already taken; re-enter slot number: "); } // If no one win or lose from both player x and 0. // then here is the logic to print "draw". if (winner.equals IgnoreCase("draw")) { System.out.println("It's a draw! Thanks for playing."); } Ln 1. Col 1 100% Windows (CRLF) I UTF-8 thingy.txt - Notepad File Edit Format View Help } } } printBoard(); winner = checkWinner(); } else { } } System.out.println("Slot already taken; re-enter slot number: "); } // If no one win or lose from both player x and 0. // then here is the logic to print "draw". if (winner.equals IgnoreCase("draw")) { System.out.println("It's a draw! Thanks for playing."); } // For winner -to display Congratulations! message. else { System.out.println("Congratulations! " + winner + "'s have won! Thanks for playing."); In 1 Col1 100% Windows (CRLE) I UTF-8 thingy.txt - Notepad File Edit Format View Help } } } printBoard(); winner = checkWinner(); } else { } } System.out.println("Slot already taken; re-enter slot number: "); } // If no one win or lose from both player x and 0. // then here is the logic to print "draw". if (winner.equals IgnoreCase("draw")) { System.out.println("It's a draw! Thanks for playing."); } // For winner -to display Congratulations! message. else { System.out.println("Congratulations! " + winner + "'s have won! Thanks for playing."); In 1 Col1 100% Windows (CRLE) I UTF-8
Expert Answer:
Related Book For
Posted Date:
Students also viewed these programming questions
-
Write a program that reads the contents of a text file. The program should create a dictionary in which the key-value pairs are described as follows: Key. The keys are the individual words found in...
-
1.1. Define a want and a need, and give an example of each. Then, explain how the relationship between wants and needs affects the way people spend money. (4 points) 2.. Identify and describe an...
-
Why doesn't the force of gravity change the speed of a bowling ball as it rolls along a bowling lane?
-
Factor the given expressions completely. W 2 b x +2 144b x
-
In July 2008, Brian, Dale, and Sandra Allen signed a contract with East Resources, Inc., concerning 148 acres of the Allens property. East wanted to develop and exploit the oil and gas resources...
-
Drew Company reports the following costs and expenses in May. InstructionsFrom the information, determine the total amount of:(a) Manufacturing overhead.(b) Product costs.(c) Period costs. Factory...
-
Solve 1 17) log81 27 18) log 32 = 16 19) log40= 20) log101=
-
two cyclists in a bicycle race have the strength to pull away from all the other cyclists in the pack. they can decide either to pull away unilaterally or to pull away conditionally. if they pull...
-
According to Elizabeth Junell, why is skimming one of the most difficult fraud schemes to detect? Explain.
-
Brianna, a nonresident of Arizona, received the following items of income this year: $40,000 in wages earned from work performed in Nevada. $400 in interest income from an account at an Arizona bank....
-
Jane brings her cat to your veterinary practice. She is seen by one of your colleagues. She tells your colleague that her cat was fine when she left for work, but when she returned home it was...
-
An airplane propeller is 2.68 m in length (from tip to tip) and has a mass of 132 kg. When the airplane's engine is first started, it applies a constant torque of 1990 Nm to the propeller, which...
-
In order to implement effective controls, when a company does not allow the person receivine cash to also deposit that cash in the bank, the company is utilizing which principle of control?
-
Land-based hotels and cruise ships have many operational similarities, there are however some differences, especially when it comes to the titles of some of the staffing positions. Identify three...
-
Refer to the information from Exercise 22-19. Use the information to determine the (1) Weighted average contribution margin , (2) Break-even point in units, and (3) Number of units of each product...
-
The computer stores a program while the program is running, as well as the data that the program is working with, in __________. a. Secondary storage b. The CPU c. Main memory d. The microprocessor
-
Assume that a program uses the named constant PI to represent the value 3.14. The program uses the named constant in several statements. What is the advantage of using the named constant instead of...
-
The following if statement determines whether choice is equal to Y or y: If (choice == 'Y' || choice == 'y') Rewrite this statement so it makes only one comparison and does not use the || operator.
-
An organist on earth is playing Bach's Toccata and Fugue in D Minor, which is being broadcast by a powerful radio antenna. Travelers in a spaceship moving at speed \(v=3 / 5 c\) away from the earth...
-
A wave equation for light is where \(\phi\) is a scalar potential. Show that the set of all linear transformations of the spacetime coordinates that permit this wave equation to be written as we did,...
-
Two spaceships with string "paradox". Consider two spaceships, both at rest in our inertial frame, a distance \(D\) apart, one behind the other. There is a light string of restlength \(D\) tied...
Study smarter with the SolutionInn App