Question: In Java please, thank you. MagicTrick.java // must be implemented // Lab 9a Notes are above. /** * Service class with supporting methods for Magic
In Java please, thank you.

MagicTrick.java // must be implemented // Lab 9a Notes are above.
/** * Service class with supporting methods for Magic Trick * * @author YOUR NAME * @version 11/02/2017 */ import java.util.*; public class MagicTrick { private int[][] grid; private int flippedRow; private int flippedCol; public static final int GRID_SIZE = 6; /** * default constructor, * sets elements in the grid to randomly generated either 0 or 1 * calls setParity method */ public MagicTrick() { // TODO // see Lab9a Notes } /** * sets elements in the last row and the last column * to either 1 or 0, so the sum of the elements in the appropriate row and column is even */ public void setParity() { // TODO // See Lab9a Notes } /** * flips the value of the randomly * selected element, saves the row and col in this.flippedRow and this.flippedCol */ public void flipOneElement() { // TODO // See Lab9a Notes } /** * accessor method * * @return the value of the row of the flipped element: this.flippedRow */ public int getFlippedRow() { // TODO return 0; // THIS IS A STUB } /** * accessor method * * @return the value of the column of the flipped element: this.flippedCol */ public int getFlippedColumn() { //TODO return 0; // THIS IS A STUB } /** * toString method returns printable version * of the content of this.grid */ public String toString() { String returnValue = ""; for (int r = 0; r GRID_SIZE; r++) { for (int c = 0; c GRID_SIZE; c++) { returnValue += this.grid[r][c] + " "; } returnValue += " "; } return returnValue += " "; } /** * checks the user's guess * * @param r - the row selected by the user * @param c - the column selected by the user * @return - true if the guessed row and column are the same * as the row and column of the flipped element */ public boolean checkGuess(int r, int c) { // TODO return false; // THIS IS A STUB } }
PlayMagicTrick.java (CLIENT)
/** * Client that plays Magic Trick * * @author YOUR NAME * @version 11/02/2017 */ import java.util.*; public class PlayMagicTrick { public static void main(String[] args) { // create a MagicTrick object MagicTrick magic = new MagicTrick(); // print the content of the grid System.out.print("The grid is: " + magic.toString()); // flip the value of the randomly selected element magic.flipOneElement(); // ask the user for the guess Scanner scan = new Scanner(System.in); System.out.print("Can you guess which element I flipped? " + magic.toString()); System.out.println("What is your guess? row (0 - " + (MagicTrick.GRID_SIZE - 1) + ") :"); int r = scan.nextInt(); System.out.println("column(0 - " + (MagicTrick.GRID_SIZE - 1) + ") :"); int c = scan.nextInt(); // check user's guess if (magic.checkGuess(r, c)) System.out.println("Congratulations, you guessed correctly!!!"); else System.out.println("Sorry the correct guess is row:" + magic.getFlippedRow() + " column:" + magic.getFlippedColumn()); } } Lab9a Notes UML Diagram CMagicTrick f& grid f&flippedRow f& flippedCol 3D' GRID-SIZE intO0 int int int MagicTrick() mgetFlippedRow( m getFlippedColumn(0) m% toString() m setParity (0) m flipOneElement0) mbCheckGuess(int, int) int int String void void boolean create PlayMagicTrick mmain(StringI) void Assumes the same number of rows and columns
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
