Question

Must be done in Java.

30 points! Now you are well PROBLEM 2: CHECK IT OUT! on your way! In checkers, players take turns moving their pieces. Starti

PROBLEM 1 INFORMATION AND THE CODE PROVIDED WITH IT AS WELL.

50 points! Complete this and youll have passed! PROBLEM 1: A CHECKERED PAST Checkers is played on an N XN checker board, wit

Provide the rest of the code with full comments and explanation and with proper indentation.

Use simple methods for better understanding.

Must compile.

At the end show the exact Output that's shown in the Problem 2.

CODE PROVIDED FOR PROBLEM 1:

import java.util.Scanner;

public class Problem1
{
   public static void main( String [] args )
   {
       //N denoting the size of the board
       int n;
       //B denoting the number of black pieces to be place on the board
       int b;
       //row and column position of a piece
       int r,c;
       //W denoting the number of white pieces to be place on the board
       int w;
      
       int i,j;
       Scanner in = new Scanner(System.in);
      
       n = in.nextInt();
      
       String[][] board = new String[n][n];
       //initialize the board with periods
       for(i = 0;i<n;i++)
       {
           for(j = 0;j<n;j++)
           {
               board[i][j] = ".";
           }
       }
      
       //take b and its r and c positions in one line of input
       //and remove any whitespaces at end and start, split at space to separate values
       in.nextLine();
       String[] inp = in.nextLine().trim().split(" ");
      
       //B will the first value in the splitted input stored in the string array
       b = Integer.parseInt(inp[0]);
       for(i = 1;i<2*b;i+=2)
       {
           r = Integer.parseInt(inp[i]);
           c = Integer.parseInt(inp[i+1]);
           //check for row and column exceed conditions .
           //positions must be in range of n
           if(r >=0 && r<n)
           {
               if(c >=0 && c< n)
               {
                   //set black posiiton in board
                   board[n - r - 1][c] = "*";
                  
               }
           }
       }
      
       //take W and its r and c positions in one line of input
       //and remove any whitespaces at end and start, split at space to separate values
      
       inp = in.nextLine().trim().split(" ");
      
       //W will the first value in the splitted input stored in the string array
       w = Integer.parseInt(inp[0]);
       for(i = 1; i<2*w ; i+=2)
       {
           r = Integer.parseInt(inp[i]);
           c = Integer.parseInt(inp[i+1]);
           //check for row and column exceed conditions .
           //positions must be in range of n
           if(r >=0 && r<n)
           {
               if(c >=0 && c< n)
               {
                   //set white piece position in board
                   board[n - r - 1][c] = "0";
                  
               }
           }
       }
       //finally print out the board
       for(i = 0;i<n;i++)
       {
           for(j = 0;j<n;j++)
           {
               System.out.print(board[i][j]+" ");
           }
           System.out.println();
       }
   }
}

___________________________________________________________________________________

30 points! Now you are well PROBLEM 2: CHECK IT OUT! on your way! In checkers, players take turns moving their pieces. Starting with your solution to Problem 1, extend it so that given a board size N, the positions of the black and white checkers, a sequence of valid moves, it prints out the resulting checker board. INPUT Sample Input One move The same input as in Problem 1, followed by Integer M denoting the number of moves, followed by 4M integers R, C, R2 C2 denoting the row and column of the start and end position 30 2 1 1 1 3 2 2 0 3 3 3 1 1 2 2 2 1 1 2 2 3 1 of a move l.e., the piece at R, c, is moved to R2 C2 Sample Output PROCESSING: *.0 You may assume that every move is valid The final board configuration is what is to be printed .0. OUTPUT Output is the same format as Problem 1
50 points! Complete this and you'll have passed! PROBLEM 1: A CHECKERED PAST Checkers is played on an N XN checker board, with one side playing the black pieces and the other side playing the white pieces. Given a board size N and the positions of the black and white checkers, create a program to print out the resulting checker board. INPUT Row, Column Integer N denoting the size of the board Integer B denoting the number of black pieces to be placed on the board, followed by B pairs of integers R C denoting the row and column of B black pieces Sample Input N Integer W denoting the number of white pieces to be placed on the board, followed by W pairs of integers R C denoting the row and column of W white pieces 4 3 2 1 1 1 3 2 2 3 3 W PROCESSING: The bottom left corner of the board is (0, o) and the top right corner is (N-1,N-1) (4,0) Sample Output 2 0 |(4,4) ...0 OUTPUT 0. Output an Nx N board, where an empty square is denoted by a period ., a black piece is denoted by an asterisk *', and a white piece is denoted by the letter o' 0 2 (0,0 |(0,4)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution.java package vbv import java.util.Scanner; public class Solution public static void main(String [] args) { 1TODO Aut

Code:

package vbv;
import java.util.Scanner;
public class Solution {
   public static void main(String[] args)
   {
   // TODO Auto-generated method stub
   int n,R1,C1,R2,C2,count=0,count1=0;
   Scanner sc = new Scanner(System.in);
   //input the size of the board
   System.out.print("Enter the size of board:");
   n = sc.nextInt();
   //filling the board with empty values
   char board[][] = new char[n][n];
   for(int i=0;i<n;i++)
   {
   for(int j=0;j<n;j++)
   {
   board[i][j] = '.' ;
   }
   }
  
   System.out.println("Initially the board is");
   //displaying the board
   displayBoard(board,n);
   int b,w,r,c;
   //input black pieces
   System.out.print("\nEnter number of black pieces:");
   b =sc.nextInt();
   System.out.println("Enter "+b+" pairs of R C denoting row and column");
   //placing the black pieces into the board
   for(int i=1;i<=b;i++)
   {
   r = sc.nextInt();
   c = sc.nextInt();
   board[r][c] = '*';
   }
   //input the white pieces
   System.out.print("\nEnter number of white pieces:");
   w =sc.nextInt();
   System.out.println("\nEnter "+w+" pairs of R C denoting row and column");
   //placing the white pieces into the board
   for(int i=1;i<=w;i++)
   {
   r = sc.nextInt();
   c = sc.nextInt();
   board[r][c] = 'O';
   }
   System.out.println("After putting the black and white pieces the board is");
   //displaying the board
   displayBoard(board,n);
   //For Problem 2 taking initial position and final position of pieces from user as input
   System.out.println("\n Enter R1 and C1(Initisl position) and R2 andC2 (final)");
   R1=sc.nextInt();
   C1=sc.nextInt();
   R2=sc.nextInt();
   C2=sc.nextInt();
   for(int i=0;i<n;i++)
   {
   for(int j=0;j<n;j++)
   { //This step will check if the initial position if found and if it is white piece
   if(board[i][j]==board[R1][C1])
   {
   if(board[i][j]=='O')
   {
   count++; /* If the piece is white count=1 else 0. This will help us to place the piece correctly in the next step*/
   board[i][j]='.';
   }
   }
   if(board[i][j]==board[R1][C1])
   {
   if(board[i][j]=='*')
   {
   count1++;
   board[i][j]='.';
   }
   }
   }
   }
   displayBoard(board,n);
   for(int i=0;i<n;i++)
   {
   for(int j=0;j<n;j++)
   {
   if(board[i][j]==board[R2][C2])
   {
   if(count==1)
   board[i][j]='O';// count=1 means white piece
   }
   if(board[i][j]==board[R2][C2])
   {
   if(count1==1)
   board[i][j]='*'; // count=0 means a black piece
   }
   }
   }
   System.out.println("After putting the black and white pieces the board is");
   //displaying the board
   displayBoard(board,n);
   }
   //method to display the board
   public static void displayBoard(char[][] board, int size)
   {
   for(int i=0;i<size;i++)
   {
   System.out.println();
   for(int j=0;j<size;j++)
   {
   System.out.print(board[i][j]+"\t");
   }
   }
   }
   }


Output:

@ Javadoc Declaration Console Problems Solution [Java Application] C:\Program Files (x86)Javaljre1.8.0 191\bin\javaw.exe (Jun

Add a comment
Know the answer?
Add Answer to:
Must be done in Java. PROBLEM 1 INFORMATION AND THE CODE PROVIDED WITH IT AS WELL....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Must be done in Java. PROBLEM 1 INFORMATION AND THE CODE PROVIDED WITH IT AS WELL....

    Must be done in Java. PROBLEM 1 INFORMATION AND THE CODE PROVIDED WITH IT AS WELL. Provide the rest of the code with full comments and explanation and with proper indentation. Use simple methods for better understanding. Must compile. At the end, show the exact Output that's shown in Problem 2. CODE PROVIDED FOR PROBLEM 1: import java.util.Scanner; public class Problem1 {    public static void main( String [] args )    {        //N denoting the size of the board        int n;       ...

  • Must be done in Java. PROBLEM 2 INFORMATION AND THE CODE PROVIDED WITH IT AS WELL....

    Must be done in Java. PROBLEM 2 INFORMATION AND THE CODE PROVIDED WITH IT AS WELL. PROBLEM 1 INFORMATION IF YOU NEED IT AS WELL: Provide the rest of the code with full comments and explanation and with proper indentation. Use simple methods for better understanding. Must compile. At the end, show the exact Output that's shown in Problem3. CODE PROVIDED FOR PROBLEM 2: import java.util.Scanner; public class Problem2 { public static void main( String [] args ) { //N...

  • please use JAVA to solve it. Checkers is played on an N XN checker board, with...

    please use JAVA to solve it. Checkers is played on an N XN checker board, with one side playing the black pieces and the ofther side playing the white pieces. Glven a board size N and the positions of the black and white checkers, create a program to print out the resulting checker board. INPUT Row, Column Integer N denoting the size of the board Integer B denoting the number of black pieces to be placed on the board, followed...

  • # In this file, fill in the ... parts with lines of code. Do not # create new functions. from ran...

    # In this file, fill in the ... parts with lines of code. Do not # create new functions. from random import seed, randrange P=[" ♟♜♝♞♛♚"]; L,R,BL,TL=["▌▐▄▀"] BonR=WonR=WonB=DonR=DonB=RonB=GonR=GonB=RonG='\033[1;m\033[' WonR+='7;31;47m' # For drawing a white piece on a red background WonB+='7;30;47m' # For drawing a white piece on a black background DonR+='2;37;41m' # For drawing a dark piece on a red background DonB+='2;37;40m' # For drawing a dark piece on a black background GonR+='2;33;41m' # For drawing gold on a red...

  • Preferably in python but java is good too Task 1: Minimum Spanning Trees For this warm-up...

    Preferably in python but java is good too Task 1: Minimum Spanning Trees For this warm-up task you are to implement any efficient minimum spanning tree algorithm that takes a sequence of edge-weighted graphs and outputs the minimum cost weight of a spanning tree of each Input Format For this assignment we use adjacency matrices with positive integer weights. Here a zero entry at row i and column J indicates that no edge i] exists in the graph. The first...

  • How to make a reversi/othello game in JAVA? Ideally with multiple classes and without GUI You...

    How to make a reversi/othello game in JAVA? Ideally with multiple classes and without GUI You are implementing a strategy board game played by two players, Black and White. It is played on an N by N board. The winner is the player who has more discs of his color than his opponent at the end of the game. This will happen when neither of the two players has a legal move or there are no spaces left on the...

  • In Python, starting with the 8x8 board solution that will be appended here add the following...

    In Python, starting with the 8x8 board solution that will be appended here add the following functionality: 1) Add code to create a list, containing 8 lists, with each of the 8 lists containing 8 null strings as values. Call the list of lists board. code provided by prof: import turtle validMovesList=['A0','A2','A4','A6','B1','B3','B5','B7', 'C0','C2','C4','C6','D1','D3','D5','D7', 'E0','E2','E4','E6','F1','F3','F5','F7', 'G0','G2','G4','G6','H1','H3','H5','H7','quit'] def drawSquare(t,length,color): t.fillcolor(color) t.begin_fill() for num in range(4): t.forward(length) t.left(90) t.end_fill() def drawRow(t,length,color1,color2): for i in range(4): drawSquare(t,length,color1) t.forward(length) drawSquare(t,length,color2) t.forward(length) def drawCircleFilled(t,size,color): t.fillcolor(color) t.begin_fill()...

  • Please develop the following code using C programming and using the specific functions, instructi...

    Please develop the following code using C programming and using the specific functions, instructions and format given below. Again please use the functions given especially. Also don't copy any existing solution please write your own code. This is the first part of a series of two labs (Lab 7 and Lab 8) that will complete an implementation for a board-type game called Reversi (also called Othello). The goal of this lab is to write code that sets up the input...

  • Please help i need a C++ version of this code and keep getting java versions. Please...

    Please help i need a C++ version of this code and keep getting java versions. Please C++ only Purpose: This lab will give you experience harnessing an existing backtracking algorithm for the eight queens problem, and seeing its results displayed on your console window (that is, the location of standard output). Lab A mostly complete version of the eight queens problem has been provided for you to download. This version has the class Queens nearly completed. You are to provide...

  • Hello I am having trouble with a connectFour java program. this issue is in my findLocalWinner...

    Hello I am having trouble with a connectFour java program. this issue is in my findLocalWinner method, it declares a winner for horizontal wins, but not for vertical. if anyone can see what im doing wrong. public class ConnectFour { /** Number of columns on the board. */ public static final int COLUMNS = 7; /** Number of rows on the board. */ public static final int ROWS = 6; /** Character for computer player's pieces */ public static final...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT