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
-
When critically appraising evidence, the appropriate questions to ask would include the following: Why was the study done? What is the sample size? How were
-
DOUGLAS COLLEGECrim 1160 The Canadian Legal System Lisa David Criminal Law Assignment (Total 10 Marks) A. Based on the wording of the specific offence indicate the actus reus. Based onthe 4 mens rea...
-
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...
-
Show that if T: V V is a contraction or a dilation of V(Example 4 of Section 8.1), then the matrix of T with respect to any basis for V is a positive scalar multiple of the identity matrix.
-
A 1 Month B C Jul 2 Forecast Output 3 Regular 4 O/T 5 Subcont 6 7 Output-Forecast 8 9 Inventory 10 Beginning 11 Ending 12 Average 13 Cost T G E Aug Sep Oct Nov De + al 320 340 360 380 400 40 00 350...
-
Describe how nonprofits intersect with your daily life.
-
Phigam Steel purchases a machine on January 1 for $30,000. The machine has an estimated useful life of seven years, during which time it is expected to produce 114,800 units. Salvage value is...
-
ook nt int onces Exercise 18-10 (Static) Retirement of shares [LO18-5] Borner Communications' articles of incorporation authorized the issuance of 130 million common shares. The transactions...
-
Sofia Lofts case, but under a new set of assumptions on page 11 of the case. First re-read the Sofia Lofts case, then click here to download the new page 11. Specifically, you are to write up a brief...
-
Identify one company that uses a sales-order-relation production system. Explain all the logistic processes used by that company in their production Identify one company that uses a make-to-stock...
-
On January 1 , 2 0 2 3 Parent held merchandise acquired from Subsidiary for $ 4 0 , 0 0 0 . During 2 0 1 3 Subsidiary sold merchandise to Parent for $ 1 2 0 , 0 0 0 , of which Parent holds $ 2 0 , 0...
-
[s/m] e 0 Acceleration versus Time a1 a2 a3 -1 0 1 2 3 time [s] a2 4 a1 5 = 0, 0 Suppose an object moves in one dimension, starting from rest at time t 6 [The acceleration values ... 0.70 m/s^2; 1.55...
-
The daily requirements for highway patrol officers in Bulloch County over the week are given below: Day Requirement 10 1 2 13 14 15 16 17 18 19 20 21 22 Officer 1 2 3 4 5 6 7 8 9 10 11 Capacity...
-
Q2. Show that tan-1/2+tan-12/11 = tan-13/4. 18 0 2 -21 Q3. If A=4 -2 and B = 4 2 then find the value of X, where 2A + 3x = = 5B. 3 -5 1
-
11. A cell of emf 'E' is connected a resistance R. The potential difference between the terminals of the cell is found to be V. The internal resistance of the cell must be : 2(E-V)v 2(E-V)R (1) (2) R...
-
Express the direction 7 3 deg counterclockwise from the positive x - axis in the following different ways. For this problem north is positive y and east is positive x . a ) north of east b ) above...
-
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.
-
Omaha, Inc., recorded certain capital stock transactions shown in the following journal entries: (1) issued common stock for \(\$ 40\) cash per share, (2) purchased treasury shares at \(\$ 50\) per...
-
Kitch Corporation has 50,000 shares of \(\$ 5\) par value common stock outstanding and retained earnings of \(\$ 820,000\). The company declares a 100 percent stock dividend. The market price at the...
-
The stockholders' equity accounts of Willis Corporation at January 1 appear below: During the year, the following transactions occurred: Jan. 10 Issued 35,000 shares of common stock for \(\$ 18\)...
Study smarter with the SolutionInn App