java面向对象编程代写 java程序代写
| Lab 3: Inheritance Submit Assignment |
| Due Tuesday by 11:59pm Points 20 Submitting a file upload Available Jan 28 at 12am - Feb 19 at 12:30am 22 days |
| Objective You will be demonstrating your ability to write classes in a hierarchy to efficiently reuse code. You will also be demonstrating your ability to read and write to a text file. Overview You will simply be creating classes that contains the game logic for Tic Tac Toe and Connect Four. A main, or a test file would be the game driver, which would logically step through a game from start to finish. You do NOT need to make a game driver, you simply to need to write each method to accomplish the task at hand. To win a Tic Tac Toe game, one player must occupy n spaces in a row, column, or all diagonal spaces. To win a Connect Four game, one player must occupy four consecutive spaces horizontally, vertically, or diagonally. Requirements You will be writing two classes (TicTacToe.java and ConnectFour.java) to complete this lab. ConnectFour is a child of TicTacToe. TicTacToe will represent an n x n tic tac toe board. The board will be a two dimensional array of int's, where 0 represents an empty space, 1 represents a space occupied by player 1, and a 2 represents a place occupied by player 2. |
TicTacToe needs to include the following:
TicTacToe( int n ): Constructor that sets up a 2 dimensional array, n x n size boolean makeMove( int x, int y ): places the current player in location x, y, where x is an index between 0 and row length - 1, and y is an index between 0 and column length - 1. If there is currently another player occupying the space, no move is made, and a false is returned. If the player successfully occupies the space, a true is returned.
int turn(): returns the player number who's turn it is
int gameStatus(): returns a 0 if there are currently no winners, -1 if the game ends in a tie, a 1 if player 1 is a winner, and 2 if player 2 is a winner
boolean gameOver(): returns false if the game is still in progress
String toString(): returns a String that represents the current state of the board. Each row should be a separate line, and there should be no white space between the columns
void loadBoard(String fileName): overwrites the current contents of the board with the state of the board in the file, fileName. You may assume that fileName contains a valid TicTacToe board, where each line represents a row, and there is no white space between the columns.
void saveBoard(String fileName): writes the current state of the board to a textfile, fileName. You should use the same formatting as toString()
int checkPosition( int x, int y ): accessor method that allows access to ONE position on the board at row x and column y. If the row or column is invalid, return a -1. The reason why you should NOT return the entire board is because the board is an object, and by returning an object you are giving clients access to make changes directly, which violates our encapsulation philosophy.
**Note: You may NOT add any other public method to either classes. You may, however, add any number of PRIVATE helper methods you see appropriate.
ConnectFour is similar to TicTacToe. The difference is, you do not need to occupy an entire row, or column, you simply need to have four in a row. The other
difference is gravity determines the row number, and the player simply has a choice of the column. The purpose of utilizing inheritance is to reuse the code you already have, so think about the relationship between TicTacToe and ConnectFour before implementing ConnectFour. You will need to determine which methods you should overwrite or overload. Note: you will only need two methods and one constructor for ConnectFour.
ConnectFour should create a 6 x 6 game board. When making a move, you should specify one number, the column number, it should return true if the space can be occupied, and false if the column is "full".
ConnectFour MUST be a subclass/child of TicTacToe, and appropriate inheritance should be used to receive full credit for this assignment.
Error Checking: You can assume that the input will be valid index numbers. Please use the Test File to sanity check your code.
Error Handling: Your code must handle exceptions, such as when a file is not found.
Testing
Please be sure to test your java files using JUnit, and my test file. This will ensure that your class and methods are named correctly, and that the methods have some level of functionality. If your code passes my test file, this simply ensures you will have no compiler errors when your file is run through automation, and does not guarantee full credit for this assignment. You need to perform your own rigorous testing to ensure your logic is accurate for all allowable scenarios.
You will need to download the LAB3_INPUT.txt and save that to the root project folder for running the test file.
Submission
1) Create a folder with the following name convention
IDNUMBER_UCINETID_Lab3 (Ex: 12345678_panteater_Lab3) 2) Copy the following files into your folder
TicTacToe.java ConnectFour.java
3) Compress/Zip your folder
4) Submit your compressed folder
Grading
Your file will be run through automation, so it is important that the name of the file, class, and methods, along with the input and output types match exactly as described. If your lab has a compiler error, the reader will make every attempt to fix simple naming issues, but at a 2 point penalty per mistake. You are responsible for making sure you are submitting the correct file that compiles! If you have found that you sent the wrong file, or would like to change your submission, you may do so up until the deadline (you just have to submit a new file on Canvas). Any corrections or files sent after the deadline will not be accepted/graded.
Please DOUBLE CHECK that your code compiles, passes the JUnit tests, is named correctly, and you are submitting the correct version/file.
TicTacToe Accessor/Mutators: 2 points TicTacToe gameStatus(): 4 points
TicTacToe toString(): 2 points
TicTacToe loadBoard(String fileName): 2 points TicTacToe saveBoard(String fileName): 2 points ConnectFour Constructor: 2 points ConnectFour moves: 2 points
| Connect Four checking for status: 4 points |
