Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

x.Hmled five in a row.. like tictactoe but for this one, you need five in order

ID: 3617780 • Letter: X

Question

x.Hmled five in a row.. like tictactoe but for this one, you need five in order to win.. however this code has a minor defect.. when the next player chooses the same spot as the previous player, the board changes the symbol and the symbol that appears in the board would be the symbol that the 2nd player chose.. someone pls fix it? thanks! the symbol must not change and maybe should have an error messages indicating that the spot was already chosen..

import java.io.*;
public class FiveRow
{
    public static void main (String[] args) throws Exception

     {

          BufferedReader keyIn = new BufferedReader(new InputStreamReader(System.in));

          char[][] B = new char[5][5];       // B is for Board



          boolean win = false;

          int players;

          System.out.print("How many players are there? ");

             players = Integer.parseInt(keyIn.readLine());



          char[] c = new char[players];

             for(int i=0;i<players;i++)

                    {System.out.print("enter symbol for player "+(i+1));

                     c[i]=keyIn.readLine().charAt(0);

                        }
          System.out.println(" ");
          System.out.println("   ~~~~~~~~ 5 IN A ROW GAME ~~~~~~~~");
          System.out.println(" ");
          //initialize our board
          for(int i=0; i<5; i++)
              for(int j=0; j<5; j++)
                  B[i][j] = '-';       
          //display our board
          for (int i=0; i<5; i++)
          {
               for(int j=0; j<5; j++)
                    System.out.print(" " +B[i][j]);
               System.out.println();
           }
          for(int t=0; (t<25) && !win ; t++)
          {
             System.out.println("Player "+(t%players+1));
              System.out.print("row =");
              int row = Integer.parseInt(keyIn.readLine());
              System.out.print("column = ");
              int col = Integer.parseInt(keyIn.readLine());
               B[row][col] = c[t%players];   //alternates between players
              //display board
               for(int i=0; i<5; i++)
               {
                   for (int j=0;j<5;j++)
                    System.out.print(" " + B[i][j]);
                   System.out.println();
               }
                //check for winner
                //check rows
                 for(int i=0;i<players;i++)
                     for(int j=0;j<5;j++)
                         {int k;
                           for( k=0;k<5;k++)
                            {//System.out.println(i+" "+j+" "+k+" "+c[i]+" "+B[j][k]);
                               if(c[i]!=B[j][k]) //not that row, go to next;
                                    k=10;
                                                                }
                            if(k==5)
                                   {System.out.println(c[i]+" is the winner");
                                    System.exit(0);
            &n

Explanation / Answer

x.Xlor="red">please rate - thanks import java.io.*; public class untitled {     public static void main (String[] args) throws Exception      {           BufferedReader keyIn = new BufferedReader(new InputStreamReader(System.in));           char[][] B = new char[5][5];       // B is for Board           boolean win = false;           int players;           System.out.print("How many players are there? ");              players = Integer.parseInt(keyIn.readLine());           char[] c = new char[players];              for(int i=0;i