// Lab 2// scheirer dan// danscheirer/** * This class represents a Pawn. A Pawn has a row, a column and a color. * A Pawn one space at a time in a straight line, but cannot move backwards. * A Pawn can kill any opponent’s piece if the opponent’s piece occupies one * of the two spaces diagonally in front of the Pawn. */public class Pawn extends AbstractChessPiece { /** * Construct a Pawn object that has a row and column, and a color. * * @param row the current row of this Pawn. * @param column the current column of this Pawn. * @param color the color of this Pawn. * @throws IllegalArgumentException if this Pawn is created with a position not within the chess * board. */ public Pawn(int row, int column, Color color) throws IllegalArgumentException { super(row, column, color); if ((this.position.getRow() > 6 || this.position.getRow() < 0) || (this.position.getCol() > 6 || this.position.getCol() < 0)) { throw new IllegalArgumentException("Piece must be within the board bounds."); } } @Override public boolean canMove(int otherRow, int otherCol) throws IllegalArgumentException { if (otherRow < 0 || otherRow > 7 || otherCol < 0 || otherCol > 7) { throw new IllegalArgumentException(“The given position is off the board.”); } else { return (this.color == Color.WHITE) && ((this.position.getRow() + 1 == otherRow && this.position.getCol() == otherCol)) || ((this.color == Color.BLACK) && (( this.position.getRow() – 1 == otherRow && this.position.getCol() == otherCol))); } } @Override public boolean canKill(ChessPiece other) { if (this.color == Color.WHITE && other.getColor() != this.color) { return ((this.position.getRow() + 1 == other.getRow() && this.position.getCol() + 1 == other.getCol()) || (this.position.getRow() + 1 == other.getRow() && this.position.getCol() – 1 == other.getCol())); } else { return ((this.color == Color.BLACK && other.getColor() != this.color) && ((this.position.getRow() – 1 == other.getRow() && this.position.getCol() + 1 == other.getCol()) || (this.position.getRow() – 1 == other.getRow() && this.position.getCol() – 1 == other.getCol()))); } }}