Question: For this last project, you must implement two Java classes. One will be a Player'' class, which will simulate a game player profile, and the

For this last project, you must implement two Java classes. One will be a "Player'' class, which will "simulate" a game player profile, and the other will be a -driver program which allows two players to play the game Tic Tac Toe. Your starting point for this project will be to start a NetBeans Project named Project$. In the NetBeans New Project window, change the name of the source package from project 6 to tictactoegame, and the name of the main class from Project6 to TicTacToeGame. Once you've started the project, download and save the Board.java class I've uploaded to Canvas into your project's tictactoegame source package. Phase I: Implement the Player Class (10 points) Next, add a new Java Class to the tictactoegame source package. Make sure the class is named Player. In this Player class, declare all of the data fields and write all of the methods described in the UML diagram below:

-name: String -mark: char -wins: int -losses: int +Player() +Player(newName +Player(newName: +Player(newName:

The Java class definition that you write must implement all of the data fields (variables) and behaviors (methods) shown in the above UML class diagram. Therefore, the class you write must contain all of the following global variables, constants and methods:

Variable and constants

? A private String-type variable named name - this will represent a player's name ? A private char-type variable named mark - this will represent the player's mark (X or O) on , Tic Tac Toe board. ? Two prince int- type variables named wins and losses, which will be used to count the player's wins and losses.

Constructors ? A no-erg constructor which takes no arguments. This constructor is responsible for setting the object's name variable to a default value of ?J Doe' and setting the wins and losses variables to a default value of 0. ? AU of the constructor overloads shown in the UMl diagram above.

Public interface methods

? set Name - A method which takes one String argument and stores that argument in a Suing-type parameter named newNamt This method is responsible for setting the object's name variable to the given Newname This method should return void ? setiAlm - A method which takes one int argument and stores that argument in a int?type parameter named nowwins. This method is responsible for setting the Objects wins variable to the given newwins. This method should return void. ? sattosses - A method which takes one int argument and stores that argument in a int-type parameter named newlosses This method is responsible for setting the objects losses variable to the given newtosses. This method should return void. ? wins - A method which takes no parameters and simply increments the value of the object's wins variable by 1. This method should return void. ? loses - A method which takes no parameters and simply increments the value of the object's losses variable by 1. This method should return void. ? getName - A method which takes no arguments. This method is responsible for returning the value of the object's name variable. This method should return String. package tictactoegame; *Programmer: Benjamin Riveira *Description: This class simulates a physical board on which two pla

public void clearBoard) t for ( int i 0; ? ROWS ; ?++) { for ( int j 0; j COLUMNS ; j++) board [ ? ] [ j] = . .. { *placeMar

return true; *hasWon checks to see if the board contains three of the specified *mark on any row, column or left or right d

else if (boardroj[omark && board[0]11 mark && board[0] [2] mark) return true; // Row 1 else if (board1 0mark && board [1] [1]

-name: String -mark: char -wins: int -losses: int +Player() +Player(newName +Player(newName: +Player(newName: String, newWins: int, newLosses: int) +Player(newName: String, newWins: int, newLosses: int, newMark: char) +setName(newName : String): void +setWins(newWins: int) : void +setLosses(newLosses: : String) String, newWins: int) +setMark(newMark: +wins(): void +loses(): void +getName(): String +getWins(): int +getLosses: int +getMark(): char Player int) : void char): void blow bomar soceden bon tamsing on zest doidw b bluoda dey package tictactoegame; /** * Programmer: Benjamin Riveira * Description: This class "simulates" a physical "board" on which two players will play the game Tic Tac Toe. The board itself consists of three rows and three columns which hold char values of either ', 'X' or '0'. */ public class Board { // Private data fields and constants private char[] [] board; private final int ROWS = 3, COLUMNS = 3; /** *Board class no-arg constructor, sets up an empty board. public Board() { board new char [ROWS] [COLUMNS ] ; /** * Board class constructor overload. This constructor will * set up a board with the array of characters that is * passed to it by reference. * @param newBoard public Board (char[] [] newBoard) { if (newBoard.length == ROWS && newBoard [0].length == COLUMNS) { board newBoard; } else { } board new char [ROWS] [COLUMNS]; /** * clearBoard () method "resets" the board back to all empty spaces. public void clearBoard() { public void clearBoard() { for(int i = 0; i < ROWS; i++) { * placeMark() method places the given mark on the specified row and column, * but only if that space is empty (does not contain another mark). for (int j = 0; j < COLUMNS; j++) { board[i][j] = ''; } { * @param mark * @param row * @param column */ public void placeMark (char mark, int row, int column) { if (row >= 0 && row = 0 && column } /** } } return true; *hasWon () "checks to see" if the board contains three of the specified *mark on any row, column or left or right diagonal line on the board. * If the board contains three of the specified marks on one of those lines, the method returns a boolean value of true, signifying that the * player with the specified mark has won the round. * @param mark * @return boolean */ public boolean hasWon (char mark) { // Left to right diagonal if (board[0][0] == mark && board [1][1] board [2] [2] == mark) mark && return true; // Right to left diagonal else if (board[0][2] == mark && board [1][1] == mark && board [2] [0] == mark) return true; // Row 0 else if (board [0][0] == mark & & board [0][1] == mark && board [0] [2] == mark) return true; // Row 1 else if (board [1] [0] == mark & & board [1][1] == mark && board[1][2] == mark) return true; // Row 2 else if (board [2] [0] == mark & & board [2] [1] == mark && board [2] [2] == mark) return true; // Column 0 else if (board [0][0] == mark && board [1][0] ==mark && board [2][0] return true; == mark) else if (board[0][0] == mark && board [0] [1] == mark && board [0] [2] == mark) return true; // Row 1 else if (board [1] [0] == mark & & board [1][1] == mark && board [1] [2] == mark) return true; // Row 2 else if (board [2] [0] == mark && == mark && board [2] [2] == mark) return true; // Column 0 board [2] [1] else if (board [0][0] == mark & & board [1] [0] == mark && board [2] [0] == mark) return true; // Column 1 else if (board [0][1] == mark && board [1][1] == mark && board [2] [1] == mark) return true; // Column 2 else if (board [0][2] == mark && board [1] [2] == mark && board [2] [2] == mark) return true; return false; else } /** * drawBoard () draws the board with column and row headings as well as any marks that have been placed. */ public void drawBoard() { System.out.println(" System.out.println(" for (int i = 0; i < ROWS; i++) { board[i][j]); } System.out.print(i); for (int j = 0; j < COLUMNS; j++) { System.out.print(" | 0 1 2"); --"); } System.out.println(" "); System.out.println(" ");

Step by Step Solution

3.50 Rating (160 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To implement the Player class according to the UML diagram and project requirements follow these ste... View full answer

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 Programming Questions!