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

#JAVA Copy your ChessPiece class. Create a new application titled populateChessB

ID: 3749580 • Letter: #

Question

#JAVA

Copy your ChessPiece class.

Create a new application titled populateChessBoard that contains your main statement.

In your populateChessBoard class create 2 arrays, one to contain an array of white ChessPiece's and one for black ChessPiece's.

Use loops to initialize all the 32 appropriate chess pieces in their initial board positions.

Use another loop to printInfo each of the 32 pieces using Algebraic chess notation. See the link for more detailed information.

http://blog.chesshouse.com/how-to-read-and-write-algebraic-chess-notation/

CHESSPIECE CLASS:

class ChessPiece
{
private int row,col;
private String colorChessPiece, nameChesspiece;

public int getPositionRow() //getting position of row
{
return row;
}
public int getPositionColumn() //getting position of column
{
return col;
}
public String getColor() //getting color of a chess piece
{
return colorChessPiece;
}
public String getPieceType() //getting name of a chess piece
{
return nameChesspiece;
}
public void setPosition(int x, int y) //setting position of a chess piece
{
row = x;
col = y;
}
public void setColor(String color) //setting color of a chess piece
{
colorChessPiece = color;
}
public void setPieceType(String name) //setting name of a chess piece
{
nameChesspiece = name;
}
public void printInfo() //printing all the details of a chess piece
{
System.out.println("Chess Piece Details-");
System.out.println("---------------------");
System.out.println("Position: " + getPositionRow() + "," + getPositionColumn());
System.out.println("Color: " + getColor());
System.out.println("Name: " + getPieceType() + " ");
}
}

Explanation / Answer

Class populateChessBoard{

private string whitepiece[16];

private string blackpiece[16];

public int Initialize()

{

for(int i=0;i<whitepiece.lemgth/2;i++)

{ whitepiece[i] = "1" ; whitepiece[i] + = "A"+i ;}

for(int i=whitepiece.lemgth/2;i<whitepiece.lemgth;i++)

{ whitepiece[i] = "2" ; whitepiece[i] + = "A"+i ;}

for(int i=0;i<blakpiece.lemgth/2;i++)

{ blakpiece[i] = "1" ; blakpiece[i] + = "A"+i ;}

for(int i=blakpiece.lemgth/2;i<blakpiece.lemgth;i++)

{ blakpiece[i] = "2" ; blakpiece[i] + = "A"+i ;}

//printInfo

System.out.println("BlackPiece: ");

for(int i=0;i<blakpiece.lemgth;i++)

{

System.out.println(blackpiece[i]);

}

System.out.println("whitepiece: ");

for(int i=0;i<whitepiece.lemgth;i++)

{

System.out.println(whitepiece[i]);

}