Penn Foster 402595 – Guaranteed 100% score

Lab Price = $10
Please feel free to send us your queries at: [email protected]
Payment Methods

Add to Cart

Buy Now

View Cart


Problem Statement
Your Project #402595
In this project, you’ll create a text-based Tic-Tac-Toe game in
which each player places either an X or O mark on a ninegrid
square. An X mark is known as a cross, while an O is
called a nought. The winner is the first player to place their
mark on three contiguous squares vertically, horizontally or
diagonally across. You can read about it in more detail on
Wikipedia (http://en.wikipedia.org/wiki/Tic-tac-toe).
The output of this project will be referenced in the subsequent
graded projects for this course
1. In NetBeans, create a new Java Application project
named TicTacToeGame.
2. Add the following variable and constant declarations to
the TicTacToeGame class:
static int[][] gameboard;
static final int EMPTY = 0;
static final int NOUGHT = -1;
static final int CROSS = 1;
Note: The variable gameboard is a two-dimensional int array.
Think of it as a table with rows and columns, where a cell
can be empty (0) or contain a nought (–1) or cross (1) . The
constants EMPTY, NOUGHT, and CROSS will simplify your
code.
3. Add the following utility methods to the TicTacToeGame
class:
static void set(int val, int row, int col) throws
IllegalArgumentException {
if (gameboard[row][col] == EMPTY) gameboard[row][col] = val;
else throw new IllegalArgumentException(“Player already there!”);
}
static void displayBoard() {
for( int r = 0; r < gameboard.length; r++ ) { System.out.print(“|”); for (int c = 0; c < gameboard[r].length; c++) { switch(gameboard[r][c]) { case NOUGHT: System.out.print(“O”); break; case CROSS: System.out.print(“X”); break; default: //Empty System.out.print(“ “); } System.out.print(“|”); } System.out.println(“\n———-\n”); } } 4. Add the following method signatures to the TicTacToeGame class: 5. Define the createBoard method. 6. Define the winOrTie method. Check first for a win with rows and columns and then diagonally. Finally, check to see if there are any empty cells without a cross or naught. Note: Review the sections “Initializing Multidimensional Arrays” on pages 144–145 and “Iterating Over Multidimensional Arrays” on pages 156–158 for how to initialize and iterate through a multidimensional array. A player wins if all the cells in a row or column are the same mark or diagonally through the center. The players tie if all cells have a cross or nought, but no player has three marks horizontally, vertically, or diagonally. Return NOUGHT if nought wins, CROSS if cross wins, 0 if there’s a tie, and another value (like –2, for example) if there are empty cells on the board. 7. In the main() method, perform the following actions: a. Create the board and initialize a turn counter, player value, and game outcome. For nought, the value is –1, while 1 is the value for cross. b. While there’s no winner or tie, display the board and prompt for a row and column for the current player. static void createBoard(int rows, int cols) { //Initialize the gameboard } static boolean winOrTie() { //Determine whether X or 0 won c. Use a try/catch block to handle the exception from the set method. You can use the System.err.println method rather than the System.out.println method to output the exception. This will display the message in red. d. Display the final board and a message on which player won or if there’s a tie. 8. When completed, the contents of the main() method should resemble the following: createBoard(3,3); int turn = 0; int playerVal; int outcome; java.util.Scanner scan = new java.util.Scanner(System.in); do { displayBoard(); playerVal = (turn % 2 == 0)? NOUGHT : CROSS; if (playerVal == NOUGHT) System.out.println(“\n—O’s turn—”); else System.out.println(“\n—X’s turn—”); System.out.print(“Enter row and column:”); try { set(playerVal, scan.nextInt(), scan.nextInt()); } catch (Exception ex) {System.err.println(ex);} turn ++; outcome = winOrTie(); } while ( outcome == -2 ); displayBoard(); switch (outcome) { case NOUGHT: System.out.println(“O wins!”); break; case CROSS: System.out.println(“X wins!”); break; case 0: System.out.println(“Tie.”); break; } 9. Compile and run the project to ensure it works as expected. Try a few games to verify all wins and ties are correctly detected. The application should behave as follows in the Output window: | | | | ______ | | | | ______ | | | | ______ —O’s turn— Enter row and column:0 0 |O| | | ______ | | | | ______ | | | | ______ —X’s turn— Enter row and column:0 1 |O|X| | ______ | | | | ______ | | | | ______ —O’s turn— Enter row and column:1 1 |O|X| | ______ | |O| | ______ | | | | ______ —X’s turn— Enter row and column:2 0 |O|X| | ______ | |O| | ______ |X| | | —O’s turn— Enter row and column: 2 2. |O|X| | ______ | |O| | ______ |X| |O| O wins! SUBMISSION GUIDELINES To submit your project, you must provide the following two files: ■ TicTacToeGame.java ■ TicTacToeGame.class To find these files within NetBeans, go to the TicTacToeGame project folder. To determine this folder, right-click on TicTacToeGame project in the Projects panel. Copy the value for the Project Folder textbox using the keyboard shortcut CTRL+C. In Windows Explorer, paste the project folder path and hit the ENTER key. Copy both the TicTacToeGame.java file from the src\tictactoegame folder and the TicTacToeGame.class file from the build\tictactoegame folder to your desktop or any other temporary location.
Relevant Material
Screenshots
402595_Output
402595_Output
Instructions
* If you want to purchase multiple products then click on “Buy Now” button which will give you ADD TO CART option.Please note that the payment is done through PayPal.
* You can also use 2CO option if you want to purchase through Credit Cards/Paypal but make sure you put the correct billing information otherwise you wont be able to receive any download link.
* Your paypal has to be pre-loaded in order to complete the purchase or otherwise please discuss it with us at [email protected].
* As soon as the payment is received, download link of the solution will automatically be sent to the address used in selected payment method.
* Please check your junk mails as the download link email might go there and please be patient for the download link email. Sometimes, due to server congestion, you may receive download link with a delay.
* All the contents are compressed in one zip folder.
* In case if you get stuck at any point during the payment process, please immediately contact us at [email protected] and we will fix it with you.
* We try our best to reach back to you on immediate basis. However, please wait for atleast 8 hours for a response from our side. Afterall, we are humans.
* Comments/Feedbacks are truely welcomed and there might be some incentives for you for the next lab/quiz/assignment.
* In case of any query, please donot hesitate to contact us at [email protected].
* MOST IMPORTANT Please use the tutorials as a guide and they need NOT to be used for any submission. Just take help from the material.
******************************************** Good Luck ***************************************************
Payment Details

 

Lab Price = $10
Please feel free to send us your queries at: [email protected]
Payment Methods

Add to Cart

Buy Now

View Cart

Privacy Policy
We take your privacy seriously and will take all measures to protect your personal information.
Any personal information received will only be used to fill your order. We will not sell or redistribute your information to anyone.
Refund Policy
Incase you face any issues with the tutorial, please free to contact us on [email protected]
We will try our best to resolve the issue and if still persists we can discuss for a refund in case its required.


Leave a Reply