Need help with Java programming. How can I modified that all user inputs are under the monitoring an

Need your ASSIGNMENT done? Use our paper writing service to score better and meet your deadline.


Order a Similar Paper Order a Different Paper

Need help with Java programming. How can I modified that all user inputs are under the monitoring and management of exception handling.TicTacToe.Javaimport java.util.Scanner;import java.util.Random;public class TicTacToe { public static void main(String[] args) { Scanner s = new Scanner(System.in); // creating Scanner object for // taking user input int m; // hold move Game g = new Game(); g.showBoard(); // starting a new game and displaying board do { // keep repeating inside loop until game ends do { // prompting players for move until input is valid System.out.print(“nPlayer “); if (g.getPlayerTurn()) System.out.print(“1 – “); else System.out.print(“2 – “); System.out.print(“Enter your move (1-9): “); m = s.nextInt(); // taking user input as move System.out.println(); } while (!g.checkMove(m)); // checking for valid move g.setMove(m); // make the move g.showBoard(); // displaying game and board position } while (!g.finishedGame() && !g.gameResult()); g.declareWinner(); // declaring the winner }}Game.Javaimport java.util.Scanner;import java.util.Random; class Game { protected char[][] game = new char[3][3]; // stores ‘X’s and ‘O’s on board protected boolean playerTurn; public Game() { for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { game[i][j] = ‘ ‘; } } playerTurn = true; // setting all values on board to blank and setting // player in turn to start } public void showBoard() { System.out.println(“Game Board: Positions:”); int p = 1; // position number in board for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { // prints out game row on board System.out.print(” ” + game[i][j] + ” “); if (j < 2) System.out.print(“|”); } System.out.print(” “); for (int j = 0; j < 3; j++) { // prints out position row on board System.out.print(” ” + p + ” “); p++; if (j < 2) System.out.print(“|”); } System.out.println(); if (i < 2) { // prints out row dividing lines System.out.print(“———–“); System.out.print(” “); System.out.println(“———–“); } } } public boolean checkMove(int move) { if (move < 1 || move > 9) { System.out.println(“Error: invalid input!”); return false; // positions 1-9 are valid and accepted } if (!positionCheck(move)) { System.out.println(“Error: position already occupied!”); return false; // board position is not empty } return true; // board position is empty } public boolean positionCheck(int move) { boolean empty = true; // position status checker switch (move) { case 1: if (game[0][0] != ‘ ‘) empty = false; break; case 2: if (game[0][1] != ‘ ‘) empty = false; break; case 3: if (game[0][2] != ‘ ‘) empty = false; break; case 4: if (game[1][0] != ‘ ‘) empty = false; break; case 5: if (game[1][1] != ‘ ‘) empty = false; break; case 6: if (game[1][2] != ‘ ‘) empty = false; break; case 7: if (game[2][0] != ‘ ‘) empty = false; break; case 8: if (game[2][1] != ‘ ‘) empty = false; break; case 9: if (game[2][2] != ‘ ‘) empty = false; break; } return empty; } public boolean getPlayerTurn() { return playerTurn; } public void setMove(int move) { char m; // stores move type being added to board if (playerTurn) m = ‘X’; else m = ‘O’; switch (move) { // sets the move played case 1: game[0][0] = m; break; case 2: game[0][1] = m; break; case 3: game[0][2] = m; break; case 4: game[1][0] = m; break; case 5: game[1][1] = m; break; case 6: game[1][2] = m; break; case 7: game[2][0] = m; break; case 8: game[2][1] = m; break; case 9: game[2][2] = m; break; } playerTurn ^= true; // changing player turn from True to False or vice // versa } public boolean finishedGame() { for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (game[i][j] == ‘ ‘) return false; // empty position in board } } return true; } public boolean gameResult() { char m = ‘X’; // for player 1 initially for (int i = 0; i < 2; i++) { // checking all winning combinations going // through center of board if (game[1][1] == m) { if (game[0][1] == m && game[2][1] == m) return true; if (game[0][2] == m && game[2][0] == m) return true; if (game[1][2] == m && game[1][0] == m) return true; if (game[2][2] == m && game[0][0] == m) return true; } if (game[0][0] == m) { // checking all winning combinations going // through top left corner of board if (game[0][1] == m && game[0][2] == m) return true; if (game[1][0] == m && game[2][0] == m) return true; } if (game[2][2] == m) { // checking all winning combinations going // through bottom right corner of board if (game[1][2] == m && game[0][2] == m) return true; if (game[2][1] == m && game[2][0] == m) return true; } m = ‘O’; // switching to player 2 } return false; // no winner was found } public void declareWinner() { if (gameResult()) { // checking if there is a winner or game will be // tied System.out.print(“nPlayer “); if (!playerTurn) System.out.print(“1 “); else System.out.print(“2 “); System.out.println(“has won the game!”); } else System.out.println(“nThe game has ended in a draw!”); }}import java.util.Scanner;import java.util.Random; class Game { protected char[][] game = new char[3][3]; // stores ‘X’s and ‘O’s on board protected boolean playerTurn; public Game() { for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { game[i][j] = ‘ ‘; } } playerTurn = true; // setting all values on board to blank and setting // player in turn to start } public void showBoard() { System.out.println(“Game Board: Positions:”); int p = 1; // position number in board for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { // prints out game row on board System.out.print(” ” + game[i][j] + ” “); if (j < 2) System.out.print(“|”); } System.out.print(” “); for (int j = 0; j < 3; j++) { // prints out position row on board System.out.print(” ” + p + ” “); p++; if (j < 2) System.out.print(“|”); } System.out.println(); if (i < 2) { // prints out row dividing lines System.out.print(“———–“); System.out.print(” “); System.out.println(“———–“); } } } public boolean checkMove(int move) { if (move < 1 || move > 9) { System.out.println(“Error: invalid input!”); return false; // positions 1-9 are valid and accepted } if (!positionCheck(move)) { System.out.println(“Error: position already occupied!”); return false; // board position is not empty } return true; // board position is empty } public boolean positionCheck(int move) { boolean empty = true; // position status checker switch (move) { case 1: if (game[0][0] != ‘ ‘) empty = false; break; case 2: if (game[0][1] != ‘ ‘) empty = false; break; case 3: if (game[0][2] != ‘ ‘) empty = false; break; case 4: if (game[1][0] != ‘ ‘) empty = false; break; case 5: if (game[1][1] != ‘ ‘) empty = false; break; case 6: if (game[1][2] != ‘ ‘) empty = false; break; case 7: if (game[2][0] != ‘ ‘) empty = false; break; case 8: if (game[2][1] != ‘ ‘) empty = false; break; case 9: if (game[2][2] != ‘ ‘) empty = false; break; } return empty; } public boolean getPlayerTurn() { return playerTurn; } public void setMove(int move) { char m; // stores move type being added to board if (playerTurn) m = ‘X’; else m = ‘O’; switch (move) { // sets the move played case 1: game[0][0] = m; break; case 2: game[0][1] = m; break; case 3: game[0][2] = m; break; case 4: game[1][0] = m; break; case 5: game[1][1] = m; break; case 6: game[1][2] = m; break; case 7: game[2][0] = m; break; case 8: game[2][1] = m; break; case 9: game[2][2] = m; break; } playerTurn ^= true; // changing player turn from True to False or vice // versa } public boolean finishedGame() { for (int i = 0; i . . .