QuestionQuestion

Write a servlet that displays a 3x3 grid: at the beginning, the 9 cells in the grid are buttons, and these buttons are replaced by O or X as the game progresses. Have a message indicating the winner when there is a winner, or indicating a draw when there is no possible win, and a link to restart the game.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
       response.setContentType("text/html;charset=UTF-8");
      
       // we need to use session in this case
       HttpSession session = request.getSession();
       // setup some varialbe
       String [][] game = null; // game matrix
       String player = "X"; // player
      
       // get the current gamre from session
       if (session.getAttribute("game") != null) {
            game = (String[][]) session.getAttribute("game");            
       } else {
            // init it if it isn't there
            game = new String[3][3];
            for (int i = 0; i < 3; i++) {
                for (int j = 0; j < 3; j++) {
                   game[i][j] = "";
                }
            }
       }...
$35.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats