*** Please I need help*** The last person did not follow the program requirement
ID: 3842393 • Letter: #
Question
*** Please I need help***
The last person did not follow the program requirement. Please choose 6 of the following feature below and comment
Homework: Final Program
Summary
Build an interactive software application, a simulation, or a game.
Work Items
Submit your program as a zip file of a directory that contains all your Java source code files and your features-to-be-graded list:
1) Please submit only a single zip file via Canvas. Do not email your instructor your work.
2) Name your directory LastFirst HW Final Prog. Name the zip file of that directory the same as that directory but with a .zip extension: LastFirst HW Final Prog.zip. In both filenames, put in your own last name and first name for “Last” and “First”. You must name your directory and file this way.
3) If you’re not sure how to create a zip file of a directory, please do a Google search to find out. The process to do so will be different depending on what operating system you’re using.
4) The name of your features-to-be-graded list (see Program Requirements below) should be named LastFirst HW Final Prog Features.txt.
Program Description
Write a program that demonstrates the skills we’ve learned throughout this quarter. This type of project offers only a few guidelines, allowing you to invest as much time and polish as you want, as long as you meet the program requirements described below. You can write a simple game (e.g., tic-tac-toe, Battleship), a simulation (e.g., a zero-dimensional energy balance model of the climate), or an application (e.g., a mortgage calculator). Your main requirement is that you demonstrate six of the following features in your software program and that you comment and document your code well:
1) Functional Decomposition: Use methods (a.k.a., functions) to break up a large program into meaningful chunks, using input to and output from those functions where appropriate.
2) Looping with Repetition Control Structures: Use two of the following structures: for, while, do/while, foreach.
3) Nested Loops: Use a loop within a loop in your program. Note that this is automatically accomplished when using Multi-Dimensional Arrays.
4) Branching with Selection Control Structures: Use multiple (i.e., more than one) if/else and/or switch statements in your code. (You don’t need to use both kinds of statements. if/else means any kind of if/else statement.)
5) File I/O: Read from or write to a file in your software. Examples of this include be reading in a preset pattern for the computer opponent’s answers in a game of rock/paper/scissors, or writing a file that logs each move the player makes, effectively recording a history of the game.
6) Using Multiple Classes: Build and use more than one class in your project. Note that a class that only has a main method and does not have any instance variables or methods does not count as a “class” in this feature. Thus, if you have a driver class that only has a main method and you want credit for this feature, you need at least two other classes in addition to the driver class.
7) One-dimensional arrays: Make use of a one-dimensional array in your software. If it is a partially-filled array, keep track of its current number of live elements with an int.
8) Class Design using Access Modifiers: Make all class-wide instance variables private in your class, and provide “getters” and “setters” to get and set the data accordingly.
9) Multi-Dimensional Arrays: Make use of an array with a dimensionality greater than one.
10) Recursion: Include a recursively designed function in your software, complete with (a) the recursive step and (b) the base step. (We did not cover this in the course, but if you know how to use it and want to, I’m willing to count it as a gradable feature for this assignment.)
11) Variable Tracing and Testing: Include a method(s) that can be used to provide output for trac-ing variables for the purpose of testing whether your code is working. The method(s) should be called test-something, e.g., testStatistics. Somewhere in your program, there should be a call to that method(s). In the code you submit, that call should be commented out, but I should be able to find it.
A few thoughts: Don’t be intimidated by the requirements above. Reuse, reuse, reuse! Think about how you can you accomplish multiple goals simultaneously. For example, doesn’t reading input from a file accomplish both File I/O and Looping with Repetition Control Structures? If you don’t know where to start, take an example that looks interesting to you and start by adding to it. NB: The requirement to comment and document your code well is in addition to the six features you’ve chosen. (Also, there are additional grading rubrics listed on the Canvas page for the assignment, but those form a relatively small part of the assignment grade.)
Finally, submit a file with your source code (put it in the same directory as your source code) where you list which six of the above features you want to be graded on. Make sure you number these features from one to six; the order doesn’t matter, but I’ll use the numbering as references while grading. Make this file a plain text file and with an extension .txt.
Explanation / Answer
I have implemented a tic tac toe game which two players can play.
we have 2 classes in our code.
The role of SimulateGame class is to simulate the game using TicTacToe class.
Content of extension.txt
Content of SimulateGame.java
import java.util.Scanner;
public class SimulateGame {
public static void main(String[] args) {
TicTacToe.initializeGame();
do {
TicTacToe.play();
if (TicTacToe.hasCrossWon()) {
System.out.println("Congratulations! 'X' won!");
} else if (TicTacToe.hasZeroWon()) {
System.out.println("Congratulations! 'O' won!");
} else if (TicTacToe.isDraw()) {
System.out.println("It's a Draw! Play again");
}
} while (TicTacToe.continuePlaying());
}
}
class TicTacToe {
//constant required for the game
private static final int BLANK = 0;
private static final int CROSS = 1;
private static final int ZERO = 2;
private static final int PLAYING = 0;
private static final int CROSS_WON = 2;
private static final int ZERO_WON = 3;
private static final int DRAW = 1;
private static final int ROWS = 3;
private static final int COLUMNS = 3;
//board holding the actual game
private static int[][] gameBoard = new int[ROWS][COLUMNS];
//variable holding current states
private static int currentState;
private static int currentPlayer;
private static int currntRow;
private static int currentColumn;
private static Scanner in = new Scanner(System.in);
public static boolean hasCrossWon() {
return currentState == CROSS_WON;
}
public static boolean hasZeroWon() {
return currentState == ZERO_WON;
}
public static boolean isDraw() {
return currentState == DRAW;
}
public static boolean continuePlaying() {
return currentState == PLAYING;
}
private static boolean hasWon(int moveValue, int currentRow, int currentCol) {
return (gameBoard[currentRow][0] == moveValue && gameBoard[currentRow][1] == moveValue
&& gameBoard[currentRow][2] == moveValue
|| gameBoard[0][currentCol] == moveValue && gameBoard[1][currentCol] == moveValue
&& gameBoard[2][currentCol] == moveValue
|| currentRow == currentCol && gameBoard[0][0] == moveValue && gameBoard[1][1] == moveValue
&& gameBoard[2][2] == moveValue
|| currentRow + currentCol == 2 && gameBoard[0][2] == moveValue && gameBoard[1][1] == moveValue
&& gameBoard[2][0] == moveValue);
}
private static boolean isDrawHelper() {
for (int row = 0; row < ROWS; ++row) {
for (int col = 0; col < COLUMNS; ++col) {
if (gameBoard[row][col] == BLANK) {
return false;
}
}
}
return true;
}
private static void switchPlayer() {
currentPlayer = (currentPlayer == CROSS) ? ZERO : CROSS;
}
private static void playerMove(int moveValue) {
boolean validInput = false;
do {
if (moveValue == CROSS) {
System.out.print("Player 'X', enter move row must be [1,2,3] column must be [1,2,3]: ");
} else {
System.out.print("Player 'O', enter move row must be [1,2,3] column must be [1,2,3]: ");
}
int row = in.nextInt() - 1;
int col = in.nextInt() - 1;
if (row >= 0 && row < ROWS && col >= 0 && col < COLUMNS && gameBoard[row][col] == BLANK) {
currntRow = row;
currentColumn = col;
gameBoard[currntRow][currentColumn] = moveValue;
validInput = true;
} else {
System.out.println("The move at (" + (row + 1) + "," + (col + 1) + ") is invalid. Enter correct move!");
}
} while (!validInput);
}
public static void initializeGame() {
for (int row = 0; row < ROWS; ++row) {
for (int col = 0; col < COLUMNS; ++col) {
gameBoard[row][col] = BLANK;
}
}
currentState = PLAYING;
currentPlayer = CROSS;
}
public static void play() {
playerMove(currentPlayer);
updateGame(currentPlayer, currntRow, currentColumn);
printBoard();
switchPlayer();
}
private static void updateGame(int moveValue, int currentRow, int currentCol) {
if (hasWon(moveValue, currentRow, currentCol)) {
currentState = (moveValue == CROSS) ? CROSS_WON : ZERO_WON;
} else if (isDrawHelper()) {
currentState = DRAW;
}
}
private static void printBoard() {
for (int row = 0; row < ROWS; ++row) {
for (int col = 0; col < COLUMNS; ++col) {
printValue(gameBoard[row][col]);
if (col != COLUMNS - 1) {
System.out.print("|");
}
}
System.out.println();
if (row != ROWS - 1) {
System.out.println("----------");
}
}
System.out.println();
}
private static void printValue(int content) {
if (content == ZERO) {
System.out.print(" O ");
} else if (content == CROSS) {
System.out.print(" X ");
} else if (content == BLANK) {
System.out.print(" ");
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.